#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*/ B115200;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int /*<<< orphan*/ uartBaudrate(int /*<<< orphan*/);
char *uartCommand(char *);
int uartConnect(char *);
int /*<<< orphan*/ uartDisconnect();
int main(int argc, char *argv[]) {
  char *retString;
  if (argc != 2) {
    printf("input command\n");
    exit(1);
  }
  if (uartConnect("/dev/ttyUSB0") == -1) {
    return -1;
  }
  uartBaudrate(B115200);
  retString = uartCommand(argv[1]);
  printf("ret String\n");
  printf("%s", retString);
  printf("len = %d\n", (int)strlen(retString));
  free(retString);
  uartDisconnect();
  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     11b8 <main+0x38>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe50(%rip),%rdi
call   1080 <uartConnect@plt>
cmp    $0xffffffff,%eax
jne    11d9 <main+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1248 <main+0xc8>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1090 <uartBaudrate@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <uartCommand@plt>
mov    %rax,-0x18(%rbp)
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1060 <uartDisconnect@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
jne    1220 <main+0x90>
mov    %rsi,%rbx
lea    0xe5a(%rip),%rdi
call   1090 <uartConnect@plt>
cmp    $0xffffffff,%eax
je     1212 <main+0x82>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   10a0 <uartBaudrate@plt>
mov    0x8(%rbx),%rdi
call   1080 <uartCommand@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
lea    0xe30(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe18(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1070 <uartDisconnect@plt>
jmp    1217 <main+0x87>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdfe(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"input command\0A\00"
@.str.1 = [13 x i8] c"/dev/ttyUSB0\00"
@B115200 = global i32 0
@.str.2 = [12 x i8] c"ret String\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [10 x i8] c"len = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
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 %12
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = call i32 @uartConnect(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 -1, i32* %3
br label %33
16: ; preds = %12
%17 = load i32, i32* @B115200
%18 = call i32 @uartBaudrate(i32 %17)
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i8* @uartCommand(i8* %21)
store i8* %22, i8** %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%24 = load i8*, i8** %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %6
%27 = call i64 @strlen(i8* %26)
%28 = trunc i64 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i8*, i8** %6
%31 = call i32 @free(i8* %30)
%32 = call i32 (...) @uartDisconnect()
store i32 0, i32* %3
br label %33
33: ; preds = %16, %15
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"/dev/ttyUSB0\00"
@B115200 = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [10 x i8] c"len = %d\0A\00"
@str = [11 x i8] c"ret String\00"
@str.5 = [14 x i8] c"input command\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = tail call i32 @uartConnect(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %23, label %10
10: ; preds = %7
%11 = load i32, i32* @B115200
%12 = tail call i32 @uartBaudrate(i32 %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i8* @uartCommand(i8* %14)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%18 = tail call i64 @strlen(i8* dereferenceable(1) %15)
%19 = trunc i64 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = tail call i32 @free(i8* %15)
%22 = tail call i32 (...) @uartDisconnect()
br label %23
23: ; preds = %7, %10
%24 = phi i32 [ 0, %10 ], [ -1, %7 ]
ret i32 %24
}