#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__ create_file_tpef(int, int, int, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/);
scalar_t__ delete_file(int, int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ perror(char *);
int power_up_iso(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int read_binary(int, int /*<<< orphan*/, int, char *);
scalar_t__ select_file(int, int);
scalar_t__ send_num_mask(int, char *);
int /*<<< orphan*/ serial_deinit(int);
int serial_init(char *);
scalar_t__ update_binary(int, int, int, char *);
scalar_t__ verify_PIN(int, char *);
int main() {
  int fd, atrlen, i, j, len;
  char mask[100], atr[100], data[100];
  fd = serial_init("/dev/smartpoll");
  if (send_num_mask(fd, mask) < 0) {
    perror("send_num_mask failed");
    return -1;
  }
  printf("Mask is : %s\n", mask);
  if ((atrlen = power_up_iso(fd, atr)) < 0) {
    perror("power_up_iso failed");
    return -1;
  }
  printf("ATR: ");
  for (i = 0; i < atrlen; i++)
    printf("%x ", (unsigned char)atr[i]);
  printf("\n");
  if (select_file(fd, 0x3f00) < 0) {
    printf("Select file failed\n");
    return -1;
  }
  printf("Selected file 0x3f00\n");
  data[0] = 0x47;
  data[1] = 0x46;
  data[2] = 0x55;
  data[3] = 0x39;
  data[4] = 0x38;
  data[5] = 0x49;
  data[6] = 0x90;
  data[7] = 0x63;
  if (verify_PIN(fd, data) < 0)
    return -1;
  printf("Sucessfully verified the PIN for the master file\n");
  if (create_file_tpef(fd, 0x2030, 20, 0, 0, 0, 0) < 0) {
    printf("Create file failed\n");
    return -1;
  }
  printf("Created a file 0x2030 of size 20 bytes\n");
  if (select_file(fd, 0x2030) < 0) {
    printf("Select file failed\n");
    return -1;
  }
  printf("Selected file 0x2030\n");
  if ((len = read_binary(fd, 0, 20, data)) < 0) {
    printf("read_binary failed\n");
    return -1;
  }
  printf("Data (b4 write): ");
  for (i = 0; i < len; i++)
    printf("%x ", (unsigned char)data[i]);
  printf("\n");
  memset(data, 0x05, 7);
  if (update_binary(fd, 0x5, 7, data) < 0)
    return -1;
  printf("Wrote to file 0x2030\n");
  if ((len = read_binary(fd, 0, 20, data)) < 0)
    return -1;
  printf("Data (after write): ");
  for (i = 0; i < len; i++)
    printf("%x ", (unsigned char)data[i]);
  printf("\n");
  if (select_file(fd, 0x3f00) < 0) {
    printf("Select file failed\n");
    return -1;
  }
  printf("Selected file 0x3f00\n");
  if (delete_file(fd, 0x2030) < 0) {
    printf("Delete file failed\n");
    return -1;
  }
  printf("Deleted file 0x2030\n");
  serial_deinit(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe17(%rip),%rdi
call   10f0 <serial_init@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
call   1080 <send_num_mask@plt>
cmp    $0x0,%rax
jge    121f <main+0x4f>
lea    0xe01(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    -0x80(%rbp),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0xf0(%rbp),%rsi
call   1070 <power_up_iso@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1264 <main+0x94>
lea    0xddf(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ad <main+0xdd>
movslq -0x10(%rbp),%rax
movzbl -0xf0(%rbp,%rax,1),%esi
ff
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1279 <main+0xa9>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x3f00,%esi
call   10a0 <select_file@plt>
cmp    $0x0,%rax
jge    12ec <main+0x11c>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x47,-0x160(%rbp)
movb   $0x46,-0x15f(%rbp)
movb   $0x55,-0x15e(%rbp)
movb   $0x39,-0x15d(%rbp)
movb   $0x38,-0x15c(%rbp)
movb   $0x49,-0x15b(%rbp)
movb   $0x90,-0x15a(%rbp)
movb   $0x63,-0x159(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x160(%rbp),%rsi
call   1090 <verify_PIN@plt>
cmp    $0x0,%rax
jge    1357 <main+0x187>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xd1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x2030,%esi
mov    $0x14,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   10e0 <create_file_tpef@plt>
cmp    $0x0,%rax
jge    13ab <main+0x1db>
lea    0xd14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x2030,%esi
call   10a0 <select_file@plt>
cmp    $0x0,%rax
jge    13ea <main+0x21a>
lea    0xc79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x160(%rbp),%rcx
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <read_binary@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1434 <main+0x264>
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    147d <main+0x2ad>
movslq -0x10(%rbp),%rax
movzbl -0x160(%rbp,%rax,1),%esi
ff
lea    0xbe4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1449 <main+0x279>
lea    0xbf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x160(%rbp),%rdi
mov    $0x5,%esi
mov    $0x7,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x160(%rbp),%rcx
mov    $0x5,%esi
mov    $0x7,%edx
call   10d0 <update_binary@plt>
cmp    $0x0,%rax
jge    14d0 <main+0x300>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xc4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x160(%rbp),%rcx
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <read_binary@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    150c <main+0x33c>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xc27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1555 <main+0x385>
movslq -0x10(%rbp),%rax
movzbl -0x160(%rbp,%rax,1),%esi
ff
lea    0xb0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1521 <main+0x351>
lea    0xb1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x3f00,%esi
call   10a0 <select_file@plt>
cmp    $0x0,%rax
jge    1594 <main+0x3c4>
lea    0xacf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xac9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x2030,%esi
call   1040 <delete_file@plt>
cmp    $0x0,%rax
jge    15d3 <main+0x403>
lea    0xb8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15e9 <main+0x419>
lea    0xb89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   10b0 <serial_deinit@plt>
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x160,%rsp
lea    0xdfa(%rip),%rdi
call   1110 <serial_init@plt>
mov    %eax,%r15d
lea    0xf0(%rsp),%rsi
mov    %eax,%edi
call   10a0 <send_num_mask@plt>
test   %rax,%rax
js     14d1 <main+0x2e1>
lea    0xdf7(%rip),%rdi
lea    0xf0(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x80(%rsp),%rsi
mov    %r15d,%edi
call   1090 <power_up_iso@plt>
test   %eax,%eax
js     14da <main+0x2ea>
mov    %eax,%ebp
lea    0xde9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %ebp,%ebp
je     129b <main+0xab>
mov    %ebp,%ebx
lea    0xddb(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x80(%rsp,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1280 <main+0x90>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15d,%edi
mov    $0x3f00,%esi
call   10c0 <select_file@plt>
test   %rax,%rax
js     14ab <main+0x2bb>
lea    0xe37(%rip),%rdi
call   1060 <puts@plt>
movabs $0x6390493839554647,%rax
49 90 63
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
call   10b0 <verify_PIN@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     14fa <main+0x30a>
lea    0xd7e(%rip),%rdi
call   1060 <puts@plt>
movl   $0x0,(%rsp)
mov    %r15d,%edi
mov    $0x2030,%esi
mov    $0x14,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1100 <create_file_tpef@plt>
test   %rax,%rax
js     14bf <main+0x2cf>
lea    0xd79(%rip),%rdi
call   1060 <puts@plt>
mov    %r15d,%edi
mov    $0x2030,%esi
call   10c0 <select_file@plt>
test   %rax,%rax
js     14c8 <main+0x2d8>
lea    0xd7e(%rip),%rdi
call   1060 <puts@plt>
lea    0x10(%rsp),%rcx
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <read_binary@plt>
test   %eax,%eax
js     14ee <main+0x2fe>
mov    %eax,%ebp
lea    0xcd5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %ebp,%ebp
je     13b8 <main+0x1c8>
mov    %ebp,%ebx
lea    0xcbd(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x10(%rsp,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    13a0 <main+0x1b0>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x5,%esi
mov    $0x7,%edx
call   1080 <memset@plt>
mov    %r15d,%edi
mov    $0x5,%esi
mov    $0x7,%edx
mov    %rbp,%rcx
call   10f0 <update_binary@plt>
test   %rax,%rax
js     14fa <main+0x30a>
lea    0xce6(%rip),%rdi
call   1060 <puts@plt>
lea    0x10(%rsp),%rcx
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <read_binary@plt>
test   %eax,%eax
js     14fa <main+0x30a>
mov    %eax,%ebp
lea    0xc3a(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %ebp,%ebp
je     1458 <main+0x268>
mov    %ebp,%ebx
lea    0xc10(%rip),%r12
xor    %ebp,%ebp
xchg   %ax,%ax
movzbl 0x10(%rsp,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1440 <main+0x250>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15d,%edi
mov    $0x3f00,%esi
call   10c0 <select_file@plt>
test   %rax,%rax
js     14c8 <main+0x2d8>
lea    0xc7e(%rip),%rdi
call   1060 <puts@plt>
mov    %r15d,%edi
mov    $0x2030,%esi
call   1050 <delete_file@plt>
test   %rax,%rax
js     150d <main+0x31d>
lea    0xc75(%rip),%rdi
call   1060 <puts@plt>
mov    %r15d,%edi
call   10d0 <serial_deinit@plt>
xor    %r14d,%r14d
jmp    14fa <main+0x30a>
lea    0xca9(%rip),%rdi
call   1060 <puts@plt>
mov    $0xffffffff,%r14d
jmp    14fa <main+0x30a>
lea    0xc82(%rip),%rdi
jmp    14f5 <main+0x305>
lea    0xc8c(%rip),%rdi
jmp    14f5 <main+0x305>
lea    0xb37(%rip),%rdi
jmp    14e1 <main+0x2f1>
lea    0xb51(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%r14d
jmp    14fa <main+0x30a>
lea    0xc40(%rip),%rdi
call   1060 <puts@plt>
mov    %r14d,%eax
add    $0x160,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc0e(%rip),%rdi
jmp    14f5 <main+0x305>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/smartpoll\00"
@.str.1 = [21 x i8] c"send_num_mask failed\00"
@.str.2 = [14 x i8] c"Mask is : %s\0A\00"
@.str.3 = [20 x i8] c"power_up_iso failed\00"
@.str.4 = [6 x i8] c"ATR: \00"
@.str.5 = [4 x i8] c"%x \00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [20 x i8] c"Select file failed\0A\00"
@.str.8 = [22 x i8] c"Selected file 0x3f00\0A\00"
@.str.9 = [50 x i8] c"Sucessfully verified the PIN for the master file\0A\00"
@.str.10 = [20 x i8] c"Create file failed\0A\00"
@.str.11 = [40 x i8] c"Created a file 0x2030 of size 20 bytes\0A\00"
@.str.12 = [22 x i8] c"Selected file 0x2030\0A\00"
@.str.13 = [20 x i8] c"read_binary failed\0A\00"
@.str.14 = [18 x i8] c"Data (b4 write): \00"
@.str.15 = [22 x i8] c"Wrote to file 0x2030\0A\00"
@.str.16 = [21 x i8] c"Data (after write): \00"
@.str.17 = [20 x i8] c"Delete file failed\0A\00"
@.str.18 = [21 x i8] c"Deleted file 0x2030\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca [100 x i8]
%9 = alloca [100 x i8]
store i32 0, i32* %1
%10 = call i32 @serial_init(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%13 = call i64 @send_num_mask(i32 %11, i8* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %152
17: ; preds = %0
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %2
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%22 = call i32 @power_up_iso(i32 %20, i8* %21)
store i32 %22, i32* %3
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %152
26: ; preds = %17
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %28
28: ; preds = %39, %26
%29 = load i32, i32* %4
%30 = load i32, i32* %3
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %28
42: ; preds = %28
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%44 = load i32, i32* %2
%45 = call i64 @select_file(i32 %44, i32 16128)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %152
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
store i8 71, i8* %51
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 1
store i8 70, i8* %52
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 2
store i8 85, i8* %53
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 3
store i8 57, i8* %54
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 4
store i8 56, i8* %55
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 5
store i8 73, i8* %56
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 6
store i8 -112, i8* %57
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 7
store i8 99, i8* %58
%59 = load i32, i32* %2
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%61 = call i64 @verify_PIN(i32 %59, i8* %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %49
store i32 -1, i32* %1
br label %152
64: ; preds = %49
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.9, i64 0, i64 0))
%66 = load i32, i32* %2
%67 = call i64 @create_file_tpef(i32 %66, i32 8240, i32 20, i32 0, i32 0, i32 0, i32 0)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %64
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
store i32 -1, i32* %1
br label %152
71: ; preds = %64
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0))
%73 = load i32, i32* %2
%74 = call i64 @select_file(i32 %73, i32 8240)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %152
78: ; preds = %71
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
%80 = load i32, i32* %2
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%82 = call i32 @read_binary(i32 %80, i32 0, i32 20, i8* %81)
store i32 %82, i32* %6
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %78
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0))
store i32 -1, i32* %1
br label %152
86: ; preds = %78
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %4
br label %88
88: ; preds = %99, %86
%89 = load i32, i32* %4
%90 = load i32, i32* %6
%91 = icmp slt i32 %89, %90
br i1 %91, label %92, label %102
92: ; preds = %88
%93 = load i32, i32* %4
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %94
%96 = load i8, i8* %95
%97 = zext i8 %96 to i32
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %97)
br label %99
99: ; preds = %92
%100 = load i32, i32* %4
%101 = add nsw i32 %100, 1
store i32 %101, i32* %4
br label %88
102: ; preds = %88
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%104 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%105 = call i32 @memset(i8* %104, i32 5, i32 7)
%106 = load i32, i32* %2
%107 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%108 = call i64 @update_binary(i32 %106, i32 5, i32 7, i8* %107)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %111
110: ; preds = %102
store i32 -1, i32* %1
br label %152
111: ; preds = %102
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0))
%113 = load i32, i32* %2
%114 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%115 = call i32 @read_binary(i32 %113, i32 0, i32 20, i8* %114)
store i32 %115, i32* %6
%116 = icmp slt i32 %115, 0
br i1 %116, label %117, label %118
117: ; preds = %111
store i32 -1, i32* %1
br label %152
118: ; preds = %111
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* %4
br label %120
120: ; preds = %131, %118
%121 = load i32, i32* %4
%122 = load i32, i32* %6
%123 = icmp slt i32 %121, %122
br i1 %123, label %124, label %134
124: ; preds = %120
%125 = load i32, i32* %4
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %126
%128 = load i8, i8* %127
%129 = zext i8 %128 to i32
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %129)
br label %131
131: ; preds = %124
%132 = load i32, i32* %4
%133 = add nsw i32 %132, 1
store i32 %133, i32* %4
br label %120
134: ; preds = %120
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%136 = load i32, i32* %2
%137 = call i64 @select_file(i32 %136, i32 16128)
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %134
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %152
141: ; preds = %134
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%143 = load i32, i32* %2
%144 = call i64 @delete_file(i32 %143, i32 8240)
%145 = icmp slt i64 %144, 0
br i1 %145, label %146, label %148
146: ; preds = %141
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0))
store i32 -1, i32* %1
br label %152
148: ; preds = %141
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.18, i64 0, i64 0))
%150 = load i32, i32* %2
%151 = call i32 @serial_deinit(i32 %150)
br label %152
152: ; preds = %148, %146, %139, %117, %110, %84, %76, %69, %63, %47, %24, %15
%153 = load i32, i32* %1
ret i32 %153
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/smartpoll\00"
@.str.1 = [21 x i8] c"send_num_mask failed\00"
@.str.2 = [14 x i8] c"Mask is : %s\0A\00"
@.str.3 = [20 x i8] c"power_up_iso failed\00"
@.str.4 = [6 x i8] c"ATR: \00"
@.str.5 = [4 x i8] c"%x \00"
@.str.14 = [18 x i8] c"Data (b4 write): \00"
@.str.16 = [21 x i8] c"Data (after write): \00"
@str.19 = [49 x i8] c"Sucessfully verified the PIN for the master file\00"
@str.20 = [39 x i8] c"Created a file 0x2030 of size 20 bytes\00"
@str.21 = [21 x i8] c"Selected file 0x2030\00"
@str.22 = [21 x i8] c"Wrote to file 0x2030\00"
@str.23 = [21 x i8] c"Selected file 0x3f00\00"
@str.24 = [20 x i8] c"Deleted file 0x2030\00"
@str.25 = [19 x i8] c"Delete file failed\00"
@str.27 = [19 x i8] c"read_binary failed\00"
@str.29 = [19 x i8] c"Create file failed\00"
@str.30 = [19 x i8] c"Select file failed\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @serial_init(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @send_num_mask(i32 %7, i8* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %116
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%14 = call i32 @power_up_iso(i32 %7, i8* %5)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %116
18: ; preds = %12
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i32 %14, 0
br i1 %20, label %31, label %21
21: ; preds = %18
%22 = zext i32 %14 to i64
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ 0, %21 ], [ %29, %23 ]
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %24, 1
%30 = icmp eq i64 %29, %22
br i1 %30, label %31, label %23
31: ; preds = %23, %18
%32 = call i32 @putchar(i32 10)
%33 = call i64 @select_file(i32 %7, i32 16128)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.30, i64 0, i64 0))
br label %116
37: ; preds = %31
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.23, i64 0, i64 0))
store i8 71, i8* %6
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 1
store i8 70, i8* %39
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 2
store i8 85, i8* %40
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 3
store i8 57, i8* %41
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 4
store i8 56, i8* %42
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 5
store i8 73, i8* %43
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 6
store i8 -112, i8* %44
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 7
store i8 99, i8* %45
%46 = call i64 @verify_PIN(i32 %7, i8* %6)
%47 = icmp slt i64 %46, 0
br i1 %47, label %116, label %48
48: ; preds = %37
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.19, i64 0, i64 0))
%50 = call i64 @create_file_tpef(i32 %7, i32 8240, i32 20, i32 0, i32 0, i32 0, i32 0)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.29, i64 0, i64 0))
br label %116
54: ; preds = %48
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.20, i64 0, i64 0))
%56 = call i64 @select_file(i32 %7, i32 8240)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.30, i64 0, i64 0))
br label %116
60: ; preds = %54
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.21, i64 0, i64 0))
%62 = call i32 @read_binary(i32 %7, i32 0, i32 20, i8* %6)
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.27, i64 0, i64 0))
br label %116
66: ; preds = %60
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0))
%68 = icmp eq i32 %62, 0
br i1 %68, label %79, label %69
69: ; preds = %66
%70 = zext i32 %62 to i64
br label %71
71: ; preds = %69, %71
%72 = phi i64 [ 0, %69 ], [ %77, %71 ]
%73 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %72
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %75)
%77 = add nuw nsw i64 %72, 1
%78 = icmp eq i64 %77, %70
br i1 %78, label %79, label %71
79: ; preds = %71, %66
%80 = call i32 @putchar(i32 10)
%81 = call i32 @memset(i8* %6, i32 5, i32 7)
%82 = call i64 @update_binary(i32 %7, i32 5, i32 7, i8* %6)
%83 = icmp slt i64 %82, 0
br i1 %83, label %116, label %84
84: ; preds = %79
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.22, i64 0, i64 0))
%86 = call i32 @read_binary(i32 %7, i32 0, i32 20, i8* %6)
%87 = icmp slt i32 %86, 0
br i1 %87, label %116, label %88
88: ; preds = %84
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0))
%90 = icmp eq i32 %86, 0
br i1 %90, label %101, label %91
91: ; preds = %88
%92 = zext i32 %86 to i64
br label %93
93: ; preds = %91, %93
%94 = phi i64 [ 0, %91 ], [ %99, %93 ]
%95 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %94
%96 = load i8, i8* %95
%97 = zext i8 %96 to i32
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %97)
%99 = add nuw nsw i64 %94, 1
%100 = icmp eq i64 %99, %92
br i1 %100, label %101, label %93
101: ; preds = %93, %88
%102 = call i32 @putchar(i32 10)
%103 = call i64 @select_file(i32 %7, i32 16128)
%104 = icmp slt i64 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %101
%106 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.30, i64 0, i64 0))
br label %116
107: ; preds = %101
%108 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.23, i64 0, i64 0))
%109 = call i64 @delete_file(i32 %7, i32 8240)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %107
%112 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.25, i64 0, i64 0))
br label %116
113: ; preds = %107
%114 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.24, i64 0, i64 0))
%115 = call i32 @serial_deinit(i32 %7)
br label %116
116: ; preds = %84, %79, %37, %113, %111, %105, %64, %58, %52, %35, %16, %10
%117 = phi i32 [ -1, %10 ], [ -1, %16 ], [ -1, %35 ], [ -1, %52 ], [ -1, %58 ], [ -1, %64 ], [ -1, %105 ], [ -1, %111 ], [ 0, %113 ], [ -1, %37 ], [ -1, %79 ], [ -1, %84 ]
ret i32 %117
}