#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 */
char *sig_getdatafromfile(char *, unsigned int, unsigned int *);
char *sig_getsigfromfile(char *, unsigned int, unsigned int *);
int sig_verify(char *, unsigned int, char *, unsigned int);
int sig_verifyandgetdata(char *filedata, unsigned int filelen, char **dataptr,
                         unsigned int *datalenptr) {
  char *sig, *data;
  unsigned int siglen, datalen;
  int r;
  data = sig_getdatafromfile(filedata, filelen, &datalen);
  if (!data)
    return 1;
  if (dataptr)
    *dataptr = data;
  if (datalenptr)
    *datalenptr = datalen;
  sig = sig_getsigfromfile(filedata, filelen, &siglen);
  if (!sig)
    return 1;
  r = sig_verify(data, datalen, sig, siglen);
  return r;
}


x86 assembly (clang, -O0):
<sig_verifyandgetdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x40(%rbp),%rdx
call   1040 <sig_getdatafromfile@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1172 <sig_verifyandgetdata+0x42>
movl   $0x1,-0x4(%rbp)
jmp    11e3 <sig_verifyandgetdata+0xb3>
cmpq   $0x0,-0x20(%rbp)
je     1188 <sig_verifyandgetdata+0x58>
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     119c <sig_verifyandgetdata+0x6c>
mov    -0x40(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x3c(%rbp),%rdx
call   1030 <sig_getsigfromfile@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c7 <sig_verifyandgetdata+0x97>
movl   $0x1,-0x4(%rbp)
jmp    11e3 <sig_verifyandgetdata+0xb3>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
call   1050 <sig_verify@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_verifyandgetdata>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r13
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%rdx
call   1040 <sig_getdatafromfile@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     119a <sig_verifyandgetdata+0x6a>
mov    %rax,%r15
test   %r13,%r13
je     1165 <sig_verifyandgetdata+0x35>
mov    %r15,0x0(%r13)
test   %r12,%r12
je     1171 <sig_verifyandgetdata+0x41>
mov    (%rsp),%eax
mov    %eax,(%r12)
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <sig_getsigfromfile@plt>
test   %rax,%rax
je     119a <sig_verifyandgetdata+0x6a>
mov    (%rsp),%esi
mov    0x4(%rsp),%ecx
mov    %r15,%rdi
mov    %rax,%rdx
call   1050 <sig_verify@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sig_verifyandgetdata(i8* %0, i32 %1, i8** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i32* %3, i32** %9
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = call i8* @sig_getdatafromfile(i8* %15, i32 %16, i32* %13)
store i8* %17, i8** %11
%18 = load i8*, i8** %11
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %4
store i32 1, i32* %5
br label %47
21: ; preds = %4
%22 = load i8**, i8*** %8
%23 = icmp ne i8** %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** %11
%26 = load i8**, i8*** %8
store i8* %25, i8** %26
br label %27
27: ; preds = %24, %21
%28 = load i32*, i32** %9
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %13
%32 = load i32*, i32** %9
store i32 %31, i32* %32
br label %33
33: ; preds = %30, %27
%34 = load i8*, i8** %6
%35 = load i32, i32* %7
%36 = call i8* @sig_getsigfromfile(i8* %34, i32 %35, i32* %12)
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = icmp ne i8* %37, null
br i1 %38, label %40, label %39
39: ; preds = %33
store i32 1, i32* %5
br label %47
40: ; preds = %33
%41 = load i8*, i8** %11
%42 = load i32, i32* %13
%43 = load i8*, i8** %10
%44 = load i32, i32* %12
%45 = call i32 @sig_verify(i8* %41, i32 %42, i8* %43, i32 %44)
store i32 %45, i32* %14
%46 = load i32, i32* %14
store i32 %46, i32* %5
br label %47
47: ; preds = %40, %39, %20
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
define i32 @sig_verifyandgetdata(i8* %0, i32 %1, i8** writeonly %2, i32* writeonly %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i8* @sig_getdatafromfile(i8* %0, i32 %1, i32* %6)
%10 = icmp eq i8* %9, null
br i1 %10, label %25, label %11
11: ; preds = %4
%12 = icmp eq i8** %2, null
br i1 %12, label %14, label %13
13: ; preds = %11
store i8* %9, i8** %2
br label %14
14: ; preds = %13, %11
%15 = icmp eq i32* %3, null
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = load i32, i32* %6
store i32 %17, i32* %3
br label %18
18: ; preds = %16, %14
%19 = call i8* @sig_getsigfromfile(i8* %0, i32 %1, i32* %5)
%20 = icmp eq i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* %6
%23 = load i32, i32* %5
%24 = call i32 @sig_verify(i8* %9, i32 %22, i8* %19, i32 %23)
br label %25
25: ; preds = %18, %4, %21
%26 = phi i32 [ %24, %21 ], [ 1, %4 ], [ 1, %18 ]
ret i32 %26
}