#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ strncmp(char *, char *, int);
int find_ecd_sig(char *buffer, int buflen, int *offset) {
  static char ecdsig[] = {'P', 'K', 0x05, 0x06};
  int i, found = 0;
  for (i = buflen - 22; i >= 0; i--) {
    if (!strncmp(buffer + i, ecdsig, 4)) {
      found = 1;
      *offset = i;
      break;
    }
  }
  return (!found);
}


x86 assembly (clang, -O0):
<find_ecd_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x16,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     118a <find_ecd_sig+0x7a>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0x2ed9(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1177 <find_ecd_sig+0x67>
movl   $0x1,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    118a <find_ecd_sig+0x7a>
jmp    117c <find_ecd_sig+0x6c>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1133 <find_ecd_sig+0x23>
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_ecd_sig>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%r15d
cmp    $0x16,%esi
jl     1169 <find_ecd_sig+0x59>
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%rbp
add    $0xffffffea,%ebx
lea    0x2ef3(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rbx,%rbp,1),%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1163 <find_ecd_sig+0x53>
lea    -0x1(%rbx),%rax
test   %rbx,%rbx
mov    %rax,%rbx
jg     1140 <find_ecd_sig+0x30>
jmp    1169 <find_ecd_sig+0x59>
mov    %ebx,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@find_ecd_sig.ecdsig = internal global [4 x i8] c"PK\05\06"
define i32 @find_ecd_sig(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %8
%9 = load i32, i32* %5
%10 = sub nsw i32 %9, 22
store i32 %10, i32* %7
br label %11
11: ; preds = %25, %3
%12 = load i32, i32* %7
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = call i32 @strncmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @find_ecd_sig.ecdsig, i64 0, i64 0), i32 4)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %14
store i32 1, i32* %8
%22 = load i32, i32* %7
%23 = load i32*, i32** %6
store i32 %22, i32* %23
br label %28
24: ; preds = %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %7
%27 = add nsw i32 %26, -1
store i32 %27, i32* %7
br label %11
28: ; preds = %21, %11
%29 = load i32, i32* %8
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
%32 = zext i1 %31 to i32
ret i32 %32
}

LLVM IR (-O2):
@find_ecd_sig.ecdsig = internal global [4 x i8] c"PK\05\06"
define i32 @find_ecd_sig(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = icmp sgt i32 %1, 21
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = add nsw i32 %1, -22
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %5, %15
%9 = phi i64 [ %7, %5 ], [ %17, %15 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = tail call i32 @strncmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @find_ecd_sig.ecdsig, i64 0, i64 0), i32 4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = trunc i64 %9 to i32
store i32 %14, i32* %2
br label %18
15: ; preds = %8
%16 = icmp sgt i64 %9, 0
%17 = add nsw i64 %9, -1
br i1 %16, label %8, label %18
18: ; preds = %15, %3, %13
%19 = phi i32 [ 0, %13 ], [ 1, %3 ], [ 1, %15 ]
ret i32 %19
}