#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_and_recv_loop(int);
int /*<<< orphan*/ serial_deinit(int);
int serial_init(char *);
int main(int argc, char *argv[]) {
  int serial_handle;
  if (argc != 2) {
    printf("Usage: %s <serial device name>\n", argv[0]);
    exit(-1);
  }
  printf("Smart card test program\n");
  if ((serial_handle = serial_init(argv[1])) == -1) {
    printf("Initialization failed\n");
    return 1;
  }
  send_and_recv_loop(serial_handle);
  serial_deinit(serial_handle);
  return 0;
}


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   $0x2,-0x8(%rbp)
je     118f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <serial_init@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11d0 <main+0x80>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <main+0x97>
mov    -0x14(%rbp),%edi
call   1050 <send_and_recv_loop@plt>
mov    -0x14(%rbp),%edi
call   1040 <serial_deinit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11aa <main+0x4a>
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
call   1080 <serial_init@plt>
cmp    $0xffffffff,%eax
je     1197 <main+0x37>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <send_and_recv_loop@plt>
mov    %ebx,%edi
call   1050 <serial_deinit@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    (%rbx),%rsi
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: %s <serial device name>\0A\00"
@.str.1 = [25 x i8] c"Smart card test program\0A\00"
@.str.2 = [23 x i8] c"Initialization failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @serial_init(i8* %19)
store i32 %20, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %29
24: ; preds = %15
%25 = load i32, i32* %6
%26 = call i32 @send_and_recv_loop(i32 %25)
%27 = load i32, i32* %6
%28 = call i32 @serial_deinit(i32 %27)
store i32 0, i32* %3
br label %29
29: ; preds = %24, %22
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [32 x i8] c"Usage: %s <serial device name>\0A\00"
@str = [24 x i8] c"Smart card test program\00"
@str.3 = [22 x i8] c"Initialization failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @serial_init(i8* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.3, i64 0, i64 0))
br label %19
16: ; preds = %8
%17 = tail call i32 @send_and_recv_loop(i32 %12)
%18 = tail call i32 @serial_deinit(i32 %12)
br label %19
19: ; preds = %16, %14
%20 = phi i32 [ 1, %14 ], [ 0, %16 ]
ret i32 %20
}