#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*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int applysignature(char *, char *);
int errno;
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("usage: %s <sig-file> <partition name>\n", argv[0]);
    return -3;
  }
  if (access(argv[1], F_OK) != 0) {
    printf("Fail to access %s, %s", argv[1], strerror(errno));
    return errno;
  }
  if (!(!strcmp(argv[2], "boot") || !strcmp(argv[2], "bootimg") ||
        !strcmp(argv[2], "recovery"))) {
    printf("%s partition is not supported\n", argv[2]);
    return -1;
  }
  return applysignature(argv[1], argv[2]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1282 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     11f1 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     126a <main+0x11a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe25(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     126a <main+0x11a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe10(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     126a <main+0x11a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <applysignature@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    119f <main+0x4f>
mov    0x8(%rbx),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
je     11bd <main+0x6d>
mov    0x8(%rbx),%rbx
mov    0x2e62(%rip),%r14
mov    (%r14),%edi
call   1070 <strerror@plt>
lea    0xe9a(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r14),%eax
jmp    11b5 <main+0x65>
mov    (%rbx),%rsi
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xfffffffd,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x10(%rbx),%r14
lea    0xe75(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1212 <main+0xc2>
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1212 <main+0xc2>
lea    0xe5c(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1212 <main+0xc2>
lea    0xe52(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%eax
jmp    11b5 <main+0x65>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <applysignature@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"usage: %s <sig-file> <partition name>\0A\00"
@F_OK = global i32 0
@.str.1 = [22 x i8] c"Fail to access %s, %s\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"boot\00"
@.str.3 = [8 x i8] c"bootimg\00"
@.str.4 = [9 x i8] c"recovery\00"
@.str.5 = [31 x i8] c"%s partition is not supported\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 3
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 -3, i32* %3
br label %59
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @F_OK
%18 = call i64 @access(i8* %16, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %13
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %25)
%27 = load i32, i32* @errno
store i32 %27, i32* %3
br label %59
28: ; preds = %13
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %51
34: ; preds = %28
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %51
40: ; preds = %34
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %49)
store i32 -1, i32* %3
br label %59
51: ; preds = %40, %34, %28
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 @applysignature(i8* %54, i8* %57)
store i32 %58, i32* %3
br label %59
59: ; preds = %51, %46, %20, %8
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [39 x i8] c"usage: %s <sig-file> <partition name>\0A\00"
@F_OK = global i32 0
@.str.1 = [22 x i8] c"Fail to access %s, %s\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"boot\00"
@.str.3 = [8 x i8] c"bootimg\00"
@.str.4 = [9 x i8] c"recovery\00"
@.str.5 = [31 x i8] c"%s partition is not supported\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %35
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @F_OK
%11 = tail call i64 @access(i8* %9, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %7
%14 = load i8*, i8** %8
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %16)
%18 = load i32, i32* @errno
br label %35
19: ; preds = %7
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %19
%25 = tail call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = tail call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %21)
br label %35
32: ; preds = %27, %24, %19
%33 = load i8*, i8** %8
%34 = tail call i32 @applysignature(i8* %33, i8* %21)
br label %35
35: ; preds = %32, %30, %13, %4
%36 = phi i32 [ -3, %4 ], [ %18, %13 ], [ -1, %30 ], [ %34, %32 ]
ret i32 %36
}