#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*/ closeserial(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int openserial(char *);
int /*<<< orphan*/ setRTS(int, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd;
  char *serialdev = NULL;
  if (argc > 1)
    serialdev = argv[1];
  else {
    fprintf(stderr, "No serial device specified");
    return 1;
  }
  fd = openserial(serialdev);
  if (!fd) {
    fprintf(stderr, "Error while initializing %s.\n", serialdev);
    return 1;
  }
  setRTS(fd, 0);
  sleep(1);
  setRTS(fd, 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)
movq   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1189 <main+0x39>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11ac <main+0x5c>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1219 <main+0xc9>
mov    -0x20(%rbp),%rdi
call   1060 <openserial@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11e9 <main+0x99>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1219 <main+0xc9>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1040 <setRTS@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1040 <setRTS@plt>
mov    -0x14(%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   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1194 <main+0x44>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1060 <openserial@plt>
test   %eax,%eax
je     11ad <main+0x5d>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1040 <setRTS@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <setRTS@plt>
mov    %ebp,%edi
call   1030 <closeserial@plt>
jmp    11cc <main+0x7c>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11c7 <main+0x77>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"No serial device specified\00"
@.str.1 = [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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %7
br label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %34
17: ; preds = %10
%18 = load i8*, i8** %7
%19 = call i32 @openserial(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %7
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 1, i32* %3
br label %34
26: ; preds = %17
%27 = load i32, i32* %6
%28 = call i32 @setRTS(i32 %27, i32 0)
%29 = call i32 @sleep(i32 1)
%30 = load i32, i32* %6
%31 = call i32 @setRTS(i32 %30, i32 1)
%32 = load i32, i32* %6
%33 = call i32 @closeserial(i32 %32)
store i32 0, i32* %3
br label %34
34: ; preds = %26, %22, %14
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"No serial device specified\00"
@.str.1 = [30 x i8] c"Error while initializing %s.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @openserial(i8* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %20
12: ; preds = %4
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %20
15: ; preds = %4
%16 = tail call i32 @setRTS(i32 %7, i32 0)
%17 = tail call i32 @sleep(i32 1)
%18 = tail call i32 @setRTS(i32 %7, i32 1)
%19 = tail call i32 @closeserial(i32 %7)
br label %20
20: ; preds = %15, %12, %9
%21 = phi i32 [ 0, %15 ], [ 1, %12 ], [ 1, %9 ]
ret i32 %21
}