#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 atoi(char *);
int /*<<< orphan*/ closeserial(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int openserial(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int arg_seconds;
  int fd;
  char *serialdev = (argv[2]);
  if (argc > 1) {
    arg_seconds = atoi(argv[1]);
  } else {
    printf("Please introduce the sleep time in seconds: ./serial X \n");
    return 1;
  }
  if ((argv[2] == 0)) {
    printf("Please add a /dev/ttyXX terminal to be used by serial. \n");
    return 1;
  }
  fd = openserial(serialdev, arg_seconds);
  if (!fd) {
    fprintf(stderr, "Error while initializing %s.\n", serialdev);
    return 1;
  }
  closeserial(fd);
  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)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    11a9 <main+0x59>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121d <main+0xcd>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jne    11d0 <main+0x80>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121d <main+0xcd>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <openserial@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    120e <main+0xbe>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe75(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121d <main+0xcd>
mov    -0x18(%rbp),%edi
call   1030 <closeserial@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jl     1181 <main+0x31>
mov    0x10(%rsi),%rbx
test   %rbx,%rbx
je     118a <main+0x3a>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <openserial@plt>
test   %eax,%eax
je     119d <main+0x4d>
mov    %eax,%edi
call   1040 <closeserial@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe96(%rip),%rdi
jmp    1191 <main+0x41>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
jmp    1196 <main+0x46>

LLVM IR (-O0):
@.str = [57 x i8] c"Please introduce the sleep time in seconds: ./serial X \0A\00"
@.str.1 = [57 x i8] c"Please add a /dev/ttyXX terminal to be used by serial. \0A\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Error while initializing %s.\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 2
%11 = load i8*, i8** %10
store i8* %11, i8** %8
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
br label %21
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %41
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %41
28: ; preds = %21
%29 = load i8*, i8** %8
%30 = load i32, i32* %6
%31 = call i32 @openserial(i8* %29, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %8
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %36)
store i32 1, i32* %3
br label %41
38: ; preds = %28
%39 = load i32, i32* %7
%40 = call i32 @closeserial(i32 %39)
store i32 0, i32* %3
br label %41
41: ; preds = %38, %34, %26, %19
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.2 = [30 x i8] c"Error while initializing %s.\0A\00"
@str = [56 x i8] c"Please introduce the sleep time in seconds: ./serial X \00"
@str.3 = [56 x i8] c"Please add a /dev/ttyXX terminal to be used by serial. \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 2
%4 = load i8*, i8** %3
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = icmp eq i8* %4, null
br i1 %7, label %10, label %12
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %23
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.3, i64 0, i64 0))
br label %23
12: ; preds = %6
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = tail call i32 @openserial(i8* %4, i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %23
21: ; preds = %12
%22 = tail call i32 @closeserial(i32 %16)
br label %23
23: ; preds = %21, %18, %10, %8
%24 = phi i32 [ 1, %10 ], [ 0, %21 ], [ 1, %18 ], [ 1, %8 ]
ret i32 %24
}