#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 open_port(int, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ set_opt(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int fd = 0;
  int i;
  unsigned char temp = 0;
  if ((fd = open_port(fd, "/dev/ttyUSB0")) < 0) {
    printf("open port error\n");
    return 0;
  }
  if (set_opt(fd) < 0) {
    printf("set mode error\n");
    return -1;
  }
  for (i = 0; i < 8; i++) {
    temp = 0x01 << i;
    write(fd, &temp, 1);
    sleep(3);
  }
}


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)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x14(%rbp),%edi
lea    0xe85(%rip),%rsi
call   1060 <open_port@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11a4 <main+0x54>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1215 <main+0xc5>
mov    -0x14(%rbp),%edi
call   1050 <set_opt@plt>
cmp    $0x0,%rax
jge    11ce <main+0x7e>
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <main+0xc5>
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    1215 <main+0xc5>
mov    -0x18(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %al,-0x19(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d5 <main+0x85>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea1(%rip),%rsi
xor    %ebp,%ebp
xor    %edi,%edi
call   1060 <open_port@plt>
test   %eax,%eax
js     127b <main+0x12b>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <set_opt@plt>
test   %rax,%rax
js     1289 <main+0x139>
movb   $0x1,0xf(%rsp)
lea    0xf(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
movb   $0x2,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
movb   $0x4,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
movb   $0x8,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
movb   $0x10,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
movb   $0x20,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
movb   $0x40,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
movb   $0x80,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
xor    %ebp,%ebp
jmp    129a <main+0x14a>
lea    0xd9a(%rip),%rdi
call   1030 <puts@plt>
jmp    129a <main+0x14a>
lea    0xd7d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@.str.1 = [17 x i8] c"open port error\0A\00"
@.str.2 = [16 x i8] c"set mode error\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
store i32 0, i32* %6
store i8 0, i8* %8
%9 = load i32, i32* %6
%10 = call i32 @open_port(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %34
14: ; preds = %2
%15 = load i32, i32* %6
%16 = call i64 @set_opt(i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %34
20: ; preds = %14
store i32 0, i32* %7
br label %21
21: ; preds = %31, %20
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 8
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i32, i32* %7
%26 = shl i32 1, %25
%27 = trunc i32 %26 to i8
store i8 %27, i8* %8
%28 = load i32, i32* %6
%29 = call i32 @write(i32 %28, i8* %8, i32 1)
%30 = call i32 @sleep(i32 3)
br label %31
31: ; preds = %24
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %21
34: ; preds = %12, %18, %21
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@str = [15 x i8] c"set mode error\00"
@str.3 = [16 x i8] c"open port error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = tail call i32 @open_port(i32 0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.3, i64 0, i64 0))
br label %30
8: ; preds = %2
%9 = tail call i64 @set_opt(i32 %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %8
store i8 1, i8* %3
%12 = call i32 @write(i32 %4, i8* %3, i32 1)
%13 = tail call i32 @sleep(i32 3)
store i8 2, i8* %3
%14 = call i32 @write(i32 %4, i8* %3, i32 1)
%15 = tail call i32 @sleep(i32 3)
store i8 4, i8* %3
%16 = call i32 @write(i32 %4, i8* %3, i32 1)
%17 = tail call i32 @sleep(i32 3)
store i8 8, i8* %3
%18 = call i32 @write(i32 %4, i8* %3, i32 1)
%19 = tail call i32 @sleep(i32 3)
store i8 16, i8* %3
%20 = call i32 @write(i32 %4, i8* %3, i32 1)
%21 = tail call i32 @sleep(i32 3)
store i8 32, i8* %3
%22 = call i32 @write(i32 %4, i8* %3, i32 1)
%23 = tail call i32 @sleep(i32 3)
store i8 64, i8* %3
%24 = call i32 @write(i32 %4, i8* %3, i32 1)
%25 = tail call i32 @sleep(i32 3)
store i8 -128, i8* %3
%26 = call i32 @write(i32 %4, i8* %3, i32 1)
%27 = tail call i32 @sleep(i32 3)
br label %30
28: ; preds = %8
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %11, %28, %6
%31 = phi i32 [ 0, %6 ], [ -1, %28 ], [ 0, %11 ]
ret i32 %31
}