#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int load_and_print_pubkey(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "usage: eckeytool PEM-file version\n");
    return -1;
  }
  int version = atoi(argv[2]);
  if (version < 1 || version > 255) {
    fprintf(stderr, "error: version must be in the range [1, 255].\n");
    return -2;
  }
  FILE *pemFile = fopen(argv[1], "r");
  if (!pemFile) {
    fprintf(stderr, "error: couldn't open \"%s\" for reading.\n", argv[1]);
    return -3;
  }
  int result = load_and_print_pubkey(pemFile, version);
  fclose(pemFile);
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1193 <main+0x43>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <main+0xf9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     11ba <main+0x6a>
cmpl   $0xff,-0x14(%rbp)
jle    11dd <main+0x8d>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1249 <main+0xf9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    122b <main+0xdb>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1249 <main+0xf9>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <load_and_print_pubkey@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    1195 <main+0x45>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
lea    -0x100(%r14),%eax
cmp    $0xffffff00,%eax
ja     11b3 <main+0x63>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xfffffffe,%eax
jmp    1204 <main+0xb4>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1204 <main+0xb4>
mov    0x8(%rbx),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e4 <main+0x94>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14d,%esi
call   1050 <load_and_print_pubkey@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
jmp    1204 <main+0xb4>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe5c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xfffffffd,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"usage: eckeytool PEM-file version\0A\00"
@.str.1 = [47 x i8] c"error: version must be in the range [1, 255].\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [40 x i8] c"error: couldn't open \22%s\22 for reading.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %47
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 1
br i1 %20, label %24, label %21
21: ; preds = %14
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 255
br i1 %23, label %24, label %27
24: ; preds = %21, %14
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %47
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %7
%32 = load i32*, i32** %7
%33 = icmp ne i32* %32, null
br i1 %33, label %40, label %34
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %38)
store i32 -3, i32* %3
br label %47
40: ; preds = %27
%41 = load i32*, i32** %7
%42 = load i32, i32* %6
%43 = call i32 @load_and_print_pubkey(i32* %41, i32 %42)
store i32 %43, i32* %8
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
%46 = load i32, i32* %8
store i32 %46, i32* %3
br label %47
47: ; preds = %40, %34, %24, %11
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"usage: eckeytool PEM-file version\0A\00"
@.str.1 = [47 x i8] c"error: version must be in the range [1, 255].\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [40 x i8] c"error: couldn't open \22%s\22 for reading.\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 i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %28
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = add i32 %10, -256
%12 = icmp ult i32 %11, -255
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %28
16: ; preds = %7
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %17
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %28
25: ; preds = %16
%26 = tail call i32 @load_and_print_pubkey(i32* %19, i32 %10)
%27 = tail call i32 @fclose(i32* %19)
br label %28
28: ; preds = %13, %25, %21, %4
%29 = phi i32 [ -1, %4 ], [ -2, %13 ], [ %26, %25 ], [ -3, %21 ]
ret i32 %29
}