#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 */
scalar_t__ memcmp(char *, char *, int);
int ecd_find_sig(char *buffer, int buflen, int *offset) {
  static char ecdsig[] = {'P', 'K', 0x05, 0x06};
  int i;
  for (i = buflen - 22; i >= 0; i--) {
    if (memcmp(buffer + i, ecdsig, 4) == 0) {
      *offset = i;
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ecd_find_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x16,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1184 <ecd_find_sig+0x74>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
lea    0x2ee0(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1171 <ecd_find_sig+0x61>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    118b <ecd_find_sig+0x7b>
jmp    1176 <ecd_find_sig+0x66>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    112c <ecd_find_sig+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecd_find_sig>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
cmp    $0x16,%esi
jl     116d <ecd_find_sig+0x5d>
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%rbp
add    $0xffffffea,%ebx
lea    0x2ef6(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rbx,%rbp,1),%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1164 <ecd_find_sig+0x54>
lea    -0x1(%rbx),%rax
test   %rbx,%rbx
mov    %rax,%rbx
jg     1140 <ecd_find_sig+0x30>
jmp    116d <ecd_find_sig+0x5d>
mov    %ebx,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@ecd_find_sig.ecdsig = internal global [4 x i8] c"PK\05\06"
define i32 @ecd_find_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 ], [ %16, %15 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = tail call i64 @memcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @ecd_find_sig.ecdsig, i64 0, i64 0), i32 4)
%12 = icmp eq i64 %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 = add nsw i64 %9, -1
%17 = icmp sgt i64 %9, 0
br i1 %17, label %8, label %18
18: ; preds = %15, %3, %13
%19 = phi i32 [ 1, %13 ], [ 0, %3 ], [ 0, %15 ]
ret i32 %19
}