#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 API_SWU_VerifyImage(void *, void *, size_t);
int wrap_SWU_VerifyImage(void *signature, void *data, size_t signedSize,
                         size_t *effectiveSignedSize) {
  size_t curSize = signedSize;
  int verified;
  while (curSize > 0) {
    verified = API_SWU_VerifyImage(signature, data, curSize);
    if (verified) {
      if (effectiveSignedSize != NULL) {
        *effectiveSignedSize = curSize;
      }
      return 0;
    } else {
    }
    curSize--;
  }
  return -1;
}


x86 assembly (clang, -O0):
<wrap_SWU_VerifyImage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jbe    1191 <wrap_SWU_VerifyImage+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <API_SWU_VerifyImage@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     117b <wrap_SWU_VerifyImage+0x6b>
cmpq   $0x0,-0x28(%rbp)
je     116f <wrap_SWU_VerifyImage+0x5f>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1198 <wrap_SWU_VerifyImage+0x88>
jmp    1180 <wrap_SWU_VerifyImage+0x70>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1130 <wrap_SWU_VerifyImage+0x20>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrap_SWU_VerifyImage>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r15d
test   %rdx,%rdx
je     1155 <wrap_SWU_VerifyImage+0x45>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%rbp
nop
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <API_SWU_VerifyImage@plt>
test   %eax,%eax
jne    114a <wrap_SWU_VerifyImage+0x3a>
add    $0xffffffffffffffff,%rbx
jne    1130 <wrap_SWU_VerifyImage+0x20>
jmp    1155 <wrap_SWU_VerifyImage+0x45>
xor    %r15d,%r15d
test   %r14,%r14
je     1155 <wrap_SWU_VerifyImage+0x45>
mov    %rbx,(%r14)
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wrap_SWU_VerifyImage(i8* %0, i8* %1, i64 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64* %3, i64** %9
%12 = load i64, i64* %8
store i64 %12, i64* %10
br label %13
13: ; preds = %31, %4
%14 = load i64, i64* %10
%15 = icmp ugt i64 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %13
%17 = load i8*, i8** %6
%18 = load i8*, i8** %7
%19 = load i64, i64* %10
%20 = call i32 @API_SWU_VerifyImage(i8* %17, i8* %18, i64 %19)
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %16
%24 = load i64*, i64** %9
%25 = icmp ne i64* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i64, i64* %10
%28 = load i64*, i64** %9
store i64 %27, i64* %28
br label %29
29: ; preds = %26, %23
store i32 0, i32* %5
br label %35
30: ; preds = %16
br label %31
31: ; preds = %30
%32 = load i64, i64* %10
%33 = add i64 %32, -1
store i64 %33, i64* %10
br label %13
34: ; preds = %13
store i32 -1, i32* %5
br label %35
35: ; preds = %34, %29
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
define i32 @wrap_SWU_VerifyImage(i8* %0, i8* %1, i64 %2, i64* writeonly %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %16, label %6
6: ; preds = %4, %13
%7 = phi i64 [ %14, %13 ], [ %2, %4 ]
%8 = tail call i32 @API_SWU_VerifyImage(i8* %0, i8* %1, i64 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = icmp eq i64* %3, null
br i1 %11, label %16, label %12
12: ; preds = %10
store i64 %7, i64* %3
br label %16
13: ; preds = %6
%14 = add i64 %7, -1
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %6
16: ; preds = %13, %4, %10, %12
%17 = phi i32 [ 0, %12 ], [ 0, %10 ], [ -1, %4 ], [ -1, %13 ]
ret i32 %17
}