#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 */
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
int s_open(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char **argv) {
  int ser;
  int n, i;
  char str[128];
  int strlen;
  char port[64] = "/dev/ttyUSB0";
  if (argc >= 2) {
    strcpy(port, argv[1]);
  }
  strcpy(str, "blah\nyay\n");
  for (strlen = 0; (str[strlen] != 0) && (strlen < sizeof(str)); ++strlen)
    ;
  ser = s_open(port);
  if (ser < 0) {
    printf("could not open serial port: %s\n", port);
    return 1;
  } else {
    printf("serial port opened: %s\n", port);
  }
  for (i = 0; i < 256; ++i) {
    write(ser, &i, 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xf0(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
cmpl   $0x2,-0x8(%rbp)
jl     119f <main+0x4f>
lea    -0xf0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0xa4(%rbp)
movslq -0xa4(%rbp),%rax
movsbl -0xa0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xf1(%rbp)
je     11f2 <main+0xa2>
movslq -0xa4(%rbp),%rax
cmp    $0x80,%rax
setb   %al
mov    %al,-0xf1(%rbp)
mov    -0xf1(%rbp),%al
test   $0x1,%al
jne    1205 <main+0xb5>
jmp    121e <main+0xce>
jmp    120a <main+0xba>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    11bc <main+0x6c>
lea    -0xf0(%rbp),%rdi
call   1050 <s_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1256 <main+0x106>
lea    -0xf0(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a3 <main+0x153>
lea    -0xf0(%rbp),%rsi
lea    0xe06(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    129c <main+0x14c>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1270 <main+0x120>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xd0,%rsp
movaps 0xede(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
cmp    $0x2,%edi
jl     118e <main+0x4e>
mov    0x8(%rsi),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0xeab(%rip),%rsi
lea    0x50(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0x10(%rsp),%rdi
call   1050 <s_open@plt>
test   %eax,%eax
js     1202 <main+0xc2>
mov    %eax,%ebx
lea    0xeb4(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <printf@plt>
movl   $0x0,0xc(%rsp)
mov    $0x1,%ebp
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebp,0xc(%rsp)
add    $0x1,%ebp
cmp    $0x101,%ebp
jne    11e0 <main+0xa0>
xor    %eax,%eax
jmp    1218 <main+0xd8>
lea    0xe41(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.port = [64 x i8] c"/dev/ttyUSB0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [10 x i8] c"blah\0Ayay\0A\00"
@.str.1 = [32 x i8] c"could not open serial port: %s\0A\00"
@.str.2 = [24 x i8] c"serial port opened: %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 i32
%9 = alloca [128 x i8]
%10 = alloca i32
%11 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [64 x i8]* %11 to i8*
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %11, 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 @strcpy(i8* %16, i8* %19)
br label %21
21: ; preds = %15, %2
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %10
br label %24
24: ; preds = %38, %21
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = icmp ult i64 %33, 128
br label %35
35: ; preds = %31, %24
%36 = phi i1 [ false, %24 ], [ %34, %31 ]
br i1 %36, label %37, label %41
37: ; preds = %35
br label %38
38: ; preds = %37
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %24
41: ; preds = %35
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%43 = call i32 @s_open(i8* %42)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%48 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %47)
store i32 1, i32* %3
br label %63
49: ; preds = %41
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%51 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49
store i32 0, i32* %8
br label %53
53: ; preds = %59, %52
%54 = load i32, i32* %8
%55 = icmp slt i32 %54, 256
br i1 %55, label %56, label %62
56: ; preds = %53
%57 = load i32, i32* %6
%58 = call i32 @write(i32 %57, i32* %8, i32 1)
br label %59
59: ; preds = %56
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %53
62: ; preds = %53
store i32 0, i32* %3
br label %63
63: ; preds = %62, %46
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@__const.main.port = [64 x i8] c"/dev/ttyUSB0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [10 x i8] c"blah\0Ayay\0A\00"
@.str.1 = [32 x i8] c"could not open serial port: %s\0A\00"
@.str.2 = [24 x i8] c"serial port opened: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca [64 x i8]
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strcpy(i8* %8, i8* %12)
br label %14
14: ; preds = %10, %2
%15 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @s_open(i8* %8)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %27
20: ; preds = %14
%21 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %8)
store i32 0, i32* %3
br label %22
22: ; preds = %20, %22
%23 = phi i32 [ 0, %20 ], [ %25, %22 ]
%24 = call i32 @write(i32 %16, i32* %3, i32 1)
%25 = add nuw nsw i32 %23, 1
store i32 %25, i32* %3
%26 = icmp eq i32 %25, 256
br i1 %26, label %27, label %22
27: ; preds = %22, %18
%28 = phi i32 [ 1, %18 ], [ 0, %22 ]
ret i32 %28
}