#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*/ printf(char *, char *);
int /*<<< orphan*/ serial_terminal(char *, int, int /*<<< orphan*/,
                                   int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  char *devname;
  int baudrate = 0;
  int emu = 1;
  int i0 = 0;
  if (argc >= 2) {
  } else {
    printf("usage: %s <serial device> [115200|9600...]\n", argv[0]);
    return 1;
  }
  while (i0 < argc) {
    switch (i0) {
    case 1:
      devname = argv[i0];
      break;
    case 2:
      baudrate = atoi(argv[i0]);
      break;
    case 3:
      emu = atoi(argv[i0]);
      break;
    default:
      break;
    }
    i0++;
  }
  serial_terminal(devname, baudrate, 0, 0, emu);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     116a <main+0x3a>
jmp    1189 <main+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1245 <main+0x115>
jmp    118e <main+0x5e>
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122a <main+0xfa>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     11d0 <main+0xa0>
jmp    11ae <main+0x7e>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     11e5 <main+0xb5>
jmp    11bf <main+0x8f>
mov    -0x28(%rbp),%eax
sub    $0x3,%eax
je     11fe <main+0xce>
jmp    1217 <main+0xe7>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
jmp    121c <main+0xec>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    121c <main+0xec>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    121c <main+0xec>
jmp    121c <main+0xec>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118e <main+0x5e>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%r8d
xor    %ecx,%ecx
mov    %ecx,%edx
call   1040 <serial_terminal@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    $0x2,%edi
jl     119f <main+0x6f>
mov    %edi,%ebp
xor    %ebx,%ebx
mov    $0x1,%r15d
xor    %r12d,%r12d
jmp    1176 <main+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,8),%rdi
call   1050 <atoi@plt>
mov    %eax,%r12d
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11b6 <main+0x86>
cmp    $0x3,%ebx
je     1190 <main+0x60>
cmp    $0x2,%ebx
je     1160 <main+0x30>
cmp    $0x1,%ebx
jne    116d <main+0x3d>
mov    0x0(%r13,%rbx,8),%r14
jmp    116d <main+0x3d>
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,8),%rdi
call   1050 <atoi@plt>
mov    %eax,%r15d
jmp    116d <main+0x3d>
mov    0x0(%r13),%rsi
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%ebx
jmp    11ca <main+0x9a>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %r12d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15d,%r8d
call   1040 <serial_terminal@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"usage: %s <serial device> [115200|9600...]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = icmp sge i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %2
br label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %54
18: ; preds = %12
br label %19
19: ; preds = %46, %18
%20 = load i32, i32* %9
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %49
23: ; preds = %19
%24 = load i32, i32* %9
switch i32 %24, label %45 [
i32 1, label %25
i32 2, label %31
i32 3, label %38
]
25: ; preds = %23
%26 = load i8**, i8*** %5
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %6
br label %46
31: ; preds = %23
%32 = load i8**, i8*** %5
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %7
br label %46
38: ; preds = %23
%39 = load i8**, i8*** %5
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %8
br label %46
45: ; preds = %23
br label %46
46: ; preds = %45, %38, %31, %25
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %19
49: ; preds = %19
%50 = load i8*, i8** %6
%51 = load i32, i32* %7
%52 = load i32, i32* %8
%53 = call i32 @serial_terminal(i8* %50, i32 %51, i32 0, i32 0, i32 %52)
store i32 0, i32* %3
br label %54
54: ; preds = %49, %13
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [44 x i8] c"usage: %s <serial device> [115200|9600...]\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %34
9: ; preds = %4, %26
%10 = phi i64 [ 0, %4 ], [ %30, %26 ]
%11 = phi i32 [ 1, %4 ], [ %29, %26 ]
%12 = phi i32 [ 0, %4 ], [ %28, %26 ]
%13 = phi i8* [ undef, %4 ], [ %27, %26 ]
%14 = trunc i64 %10 to i32
switch i32 %14, label %26 [
i32 1, label %15
i32 2, label %18
i32 3, label %22
]
15: ; preds = %9
%16 = getelementptr inbounds i8*, i8** %1, i64 %10
%17 = load i8*, i8** %16
br label %26
18: ; preds = %9
%19 = getelementptr inbounds i8*, i8** %1, i64 %10
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
br label %26
22: ; preds = %9
%23 = getelementptr inbounds i8*, i8** %1, i64 %10
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
br label %26
26: ; preds = %9, %22, %18, %15
%27 = phi i8* [ %13, %9 ], [ %13, %22 ], [ %13, %18 ], [ %17, %15 ]
%28 = phi i32 [ %12, %9 ], [ %12, %22 ], [ %21, %18 ], [ %12, %15 ]
%29 = phi i32 [ %11, %9 ], [ %25, %22 ], [ %11, %18 ], [ %11, %15 ]
%30 = add nuw nsw i64 %10, 1
%31 = icmp eq i64 %30, %5
br i1 %31, label %32, label %9
32: ; preds = %26
%33 = tail call i32 @serial_terminal(i8* %27, i32 %28, i32 0, i32 0, i32 %29)
br label %34
34: ; preds = %32, %6
%35 = phi i32 [ 0, %32 ], [ 1, %6 ]
ret i32 %35
}