#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*/ 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, 0x1f01) < 0) {
    printf("Select file failed\n");
    return -1;
  }
  printf("Selected file 0x1f01\n");
  if ((len = read_binary(fd, 0, 50, 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, 10);
  if (update_binary(fd, 0x14, 10, data) < 0)
    return -1;
  printf("Wrote to file 0x1f01\n");
  if ((len = read_binary(fd, 0, 50, 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, 0x1f02) < 0)
    return -1;
  printf("Selected file 0x1f02\n");
  for (i = 0, j = 0; i < 0xf; i += 2)
    data[j++] = (i << 4) | (i + 1);
  if (verify_PIN(fd, data) < 0)
    return -1;
  printf("PIN verification was successfull\n");
  serial_deinit(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe37(%rip),%rdi
call   10d0 <serial_init@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
call   1070 <send_num_mask@plt>
cmp    $0x0,%rax
jge    11ff <main+0x4f>
lea    0xe21(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fb <main+0x34b>
lea    -0x80(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0xf0(%rbp),%rsi
call   1060 <power_up_iso@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1244 <main+0x94>
lea    0xdff(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fb <main+0x34b>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    128d <main+0xdd>
movslq -0x10(%rbp),%rax
movzbl -0xf0(%rbp,%rax,1),%esi
ff
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1259 <main+0xa9>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x1f01,%esi
call   1090 <select_file@plt>
cmp    $0x0,%rax
jge    12cc <main+0x11c>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fb <main+0x34b>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x160(%rbp),%rcx
xor    %esi,%esi
mov    $0x32,%edx
call   1030 <read_binary@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1316 <main+0x166>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fb <main+0x34b>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    135f <main+0x1af>
movslq -0x10(%rbp),%rax
movzbl -0x160(%rbp,%rax,1),%esi
ff
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    132b <main+0x17b>
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x160(%rbp),%rdi
mov    $0x5,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x160(%rbp),%rcx
mov    $0x14,%esi
mov    $0xa,%edx
call   10c0 <update_binary@plt>
cmp    $0x0,%rax
jge    13b2 <main+0x202>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fb <main+0x34b>
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x160(%rbp),%rcx
xor    %esi,%esi
mov    $0x32,%edx
call   1030 <read_binary@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    13ee <main+0x23e>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fb <main+0x34b>
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1437 <main+0x287>
movslq -0x10(%rbp),%rax
movzbl -0x160(%rbp,%rax,1),%esi
ff
lea    0xc2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1403 <main+0x253>
lea    0xc3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x1f02,%esi
call   1090 <select_file@plt>
cmp    $0x0,%rax
jge    1468 <main+0x2b8>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fb <main+0x34b>
lea    0xc5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xf,-0x10(%rbp)
jge    14c0 <main+0x310>
mov    -0x10(%rbp),%eax
shl    $0x4,%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
cltq
mov    %cl,-0x160(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    1484 <main+0x2d4>
mov    -0x8(%rbp),%edi
lea    -0x160(%rbp),%rsi
call   1080 <verify_PIN@plt>
cmp    $0x0,%rax
jge    14e5 <main+0x335>
movl   $0xffffffff,-0x4(%rbp)
jmp    14fb <main+0x34b>
lea    0xbf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   10a0 <serial_deinit@plt>
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x150,%rsp
lea    0xe1a(%rip),%rdi
call   10f0 <serial_init@plt>
mov    %eax,%r15d
lea    0xe0(%rsp),%rsi
mov    %eax,%edi
call   1090 <send_num_mask@plt>
test   %rax,%rax
js     1414 <main+0x244>
lea    0xe17(%rip),%rdi
lea    0xe0(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x70(%rsp),%rsi
mov    %r15d,%edi
call   1080 <power_up_iso@plt>
test   %eax,%eax
js     141d <main+0x24d>
mov    %eax,%ebp
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebp,%ebp
je     1268 <main+0x98>
mov    %ebp,%ebx
lea    0xdfe(%rip),%r14
xor    %ebp,%ebp
movzbl 0x70(%rsp,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1250 <main+0x80>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15d,%edi
mov    $0x1f01,%esi
call   10b0 <select_file@plt>
test   %rax,%rax
js     13e6 <main+0x216>
lea    0xde8(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rcx
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x32,%edx
call   1030 <read_binary@plt>
test   %eax,%eax
js     13ef <main+0x21f>
mov    %eax,%ebp
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebp,%ebp
je     12e7 <main+0x117>
mov    %ebp,%ebx
lea    0xd81(%rip),%r14
xor    %ebp,%ebp
nopl   (%rax)
movzbl (%rsp,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12d0 <main+0x100>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x5,%esi
mov    $0xa,%edx
call   1070 <memset@plt>
mov    %r15d,%edi
mov    $0x14,%esi
mov    $0xa,%edx
mov    %rbp,%rcx
call   10e0 <update_binary@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     1401 <main+0x231>
lea    0xd5b(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rcx
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x32,%edx
call   1030 <read_binary@plt>
test   %eax,%eax
js     1401 <main+0x231>
mov    %eax,%ebp
lea    0xd09(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebp,%ebp
je     1387 <main+0x1b7>
mov    %ebp,%ebx
lea    0xcdf(%rip),%r12
xor    %ebp,%ebp
nop
movzbl (%rsp,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1370 <main+0x1a0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15d,%edi
mov    $0x1f02,%esi
call   10b0 <select_file@plt>
test   %rax,%rax
js     1401 <main+0x231>
lea    0xcf7(%rip),%rdi
call   1050 <puts@plt>
movabs $0xefcdab8967452301,%rax
ab cd ef
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %r15d,%edi
call   10a0 <verify_PIN@plt>
test   %rax,%rax
js     1401 <main+0x231>
lea    0xce2(%rip),%rdi
call   1050 <puts@plt>
mov    %r15d,%edi
call   10c0 <serial_deinit@plt>
xor    %r14d,%r14d
jmp    1401 <main+0x231>
lea    0xcfd(%rip),%rdi
jmp    13f6 <main+0x226>
lea    0xce1(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x150,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbf4(%rip),%rdi
jmp    1424 <main+0x254>
lea    0xc0e(%rip),%rdi
call   10d0 <perror@plt>
jmp    13fb <main+0x22b>

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 0x1f01\0A\00"
@.str.9 = [20 x i8] c"read_binary failed\0A\00"
@.str.10 = [18 x i8] c"Data (b4 write): \00"
@.str.11 = [22 x i8] c"Wrote to file 0x1f01\0A\00"
@.str.12 = [21 x i8] c"Data (after write): \00"
@.str.13 = [22 x i8] c"Selected file 0x1f02\0A\00"
@.str.14 = [34 x i8] c"PIN verification was successfull\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 %140
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 %140
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 7937)
%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 %140
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%51 = load i32, i32* %2
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%53 = call i32 @read_binary(i32 %51, i32 0, i32 50, i8* %52)
store i32 %53, i32* %6
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %49
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
store i32 -1, i32* %1
br label %140
57: ; preds = %49
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %4
br label %59
59: ; preds = %70, %57
%60 = load i32, i32* %4
%61 = load i32, i32* %6
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %73
63: ; preds = %59
%64 = load i32, i32* %4
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %63
%71 = load i32, i32* %4
%72 = add nsw i32 %71, 1
store i32 %72, i32* %4
br label %59
73: ; preds = %59
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%76 = call i32 @memset(i8* %75, i32 5, i32 10)
%77 = load i32, i32* %2
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%79 = call i64 @update_binary(i32 %77, i32 20, i32 10, i8* %78)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %73
store i32 -1, i32* %1
br label %140
82: ; preds = %73
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0))
%84 = load i32, i32* %2
%85 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%86 = call i32 @read_binary(i32 %84, i32 0, i32 50, i8* %85)
store i32 %86, i32* %6
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %89
88: ; preds = %82
store i32 -1, i32* %1
br label %140
89: ; preds = %82
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %4
br label %91
91: ; preds = %102, %89
%92 = load i32, i32* %4
%93 = load i32, i32* %6
%94 = icmp slt i32 %92, %93
br i1 %94, label %95, label %105
95: ; preds = %91
%96 = load i32, i32* %4
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %97
%99 = load i8, i8* %98
%100 = zext i8 %99 to i32
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %100)
br label %102
102: ; preds = %95
%103 = load i32, i32* %4
%104 = add nsw i32 %103, 1
store i32 %104, i32* %4
br label %91
105: ; preds = %91
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%107 = load i32, i32* %2
%108 = call i64 @select_file(i32 %107, i32 7938)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %111
110: ; preds = %105
store i32 -1, i32* %1
br label %140
111: ; preds = %105
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %4
store i32 0, i32* %5
br label %113
113: ; preds = %127, %111
%114 = load i32, i32* %4
%115 = icmp slt i32 %114, 15
br i1 %115, label %116, label %130
116: ; preds = %113
%117 = load i32, i32* %4
%118 = shl i32 %117, 4
%119 = load i32, i32* %4
%120 = add nsw i32 %119, 1
%121 = or i32 %118, %120
%122 = trunc i32 %121 to i8
%123 = load i32, i32* %5
%124 = add nsw i32 %123, 1
store i32 %124, i32* %5
%125 = sext i32 %123 to i64
%126 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %125
store i8 %122, i8* %126
br label %127
127: ; preds = %116
%128 = load i32, i32* %4
%129 = add nsw i32 %128, 2
store i32 %129, i32* %4
br label %113
130: ; preds = %113
%131 = load i32, i32* %2
%132 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%133 = call i64 @verify_PIN(i32 %131, i8* %132)
%134 = icmp slt i64 %133, 0
br i1 %134, label %135, label %136
135: ; preds = %130
store i32 -1, i32* %1
br label %140
136: ; preds = %130
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.14, i64 0, i64 0))
%138 = load i32, i32* %2
%139 = call i32 @serial_deinit(i32 %138)
br label %140
140: ; preds = %136, %135, %110, %88, %81, %55, %47, %24, %15
%141 = load i32, i32* %1
ret i32 %141
}

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.10 = [18 x i8] c"Data (b4 write): \00"
@.str.12 = [21 x i8] c"Data (after write): \00"
@str = [21 x i8] c"Selected file 0x1f01\00"
@str.15 = [21 x i8] c"Wrote to file 0x1f01\00"
@str.16 = [21 x i8] c"Selected file 0x1f02\00"
@str.17 = [33 x i8] c"PIN verification was successfull\00"
@str.18 = [19 x i8] c"read_binary failed\00"
@str.19 = [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 %96
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 %96
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 7937)
%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.19, i64 0, i64 0))
br label %96
37: ; preds = %31
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%39 = call i32 @read_binary(i32 %7, i32 0, i32 50, i8* %6)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.18, i64 0, i64 0))
br label %96
43: ; preds = %37
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
%45 = icmp eq i32 %39, 0
br i1 %45, label %56, label %46
46: ; preds = %43
%47 = zext i32 %39 to i64
br label %48
48: ; preds = %46, %48
%49 = phi i64 [ 0, %46 ], [ %54, %48 ]
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = add nuw nsw i64 %49, 1
%55 = icmp eq i64 %54, %47
br i1 %55, label %56, label %48
56: ; preds = %48, %43
%57 = call i32 @putchar(i32 10)
%58 = call i32 @memset(i8* %6, i32 5, i32 10)
%59 = call i64 @update_binary(i32 %7, i32 20, i32 10, i8* %6)
%60 = icmp slt i64 %59, 0
br i1 %60, label %96, label %61
61: ; preds = %56
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.15, i64 0, i64 0))
%63 = call i32 @read_binary(i32 %7, i32 0, i32 50, i8* %6)
%64 = icmp slt i32 %63, 0
br i1 %64, label %96, label %65
65: ; preds = %61
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
%67 = icmp eq i32 %63, 0
br i1 %67, label %78, label %68
68: ; preds = %65
%69 = zext i32 %63 to i64
br label %70
70: ; preds = %68, %70
%71 = phi i64 [ 0, %68 ], [ %76, %70 ]
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %74)
%76 = add nuw nsw i64 %71, 1
%77 = icmp eq i64 %76, %69
br i1 %77, label %78, label %70
78: ; preds = %70, %65
%79 = call i32 @putchar(i32 10)
%80 = call i64 @select_file(i32 %7, i32 7938)
%81 = icmp slt i64 %80, 0
br i1 %81, label %96, label %82
82: ; preds = %78
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.16, i64 0, i64 0))
store i8 1, i8* %6
%84 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 1
store i8 35, i8* %84
%85 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 2
store i8 69, i8* %85
%86 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 3
store i8 103, i8* %86
%87 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 4
store i8 -119, i8* %87
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 5
store i8 -85, i8* %88
%89 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 6
store i8 -51, i8* %89
%90 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 7
store i8 -17, i8* %90
%91 = call i64 @verify_PIN(i32 %7, i8* %6)
%92 = icmp slt i64 %91, 0
br i1 %92, label %96, label %93
93: ; preds = %82
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.17, i64 0, i64 0))
%95 = call i32 @serial_deinit(i32 %7)
br label %96
96: ; preds = %82, %78, %61, %56, %93, %41, %35, %16, %10
%97 = phi i32 [ -1, %10 ], [ -1, %16 ], [ -1, %35 ], [ -1, %41 ], [ 0, %93 ], [ -1, %56 ], [ -1, %61 ], [ -1, %78 ], [ -1, %82 ]
ret i32 %97
}