#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
int write(int, int *, int);
int main() {
  int fd = 0;
  int ret = 0;
  if ((fd = open("/dev/led_by_EOF", O_RDWR)) < 0) {
    printf("line %d open failed\n", 28);
    return 0;
  }
  int buf = 0;
  int time = 0;
  buf = 0x0;
  for (time = 0, buf = 0; time < 5; time++) {
    if ((ret = write(fd, &buf, sizeof(buf))) < 0) {
      printf("write error!\n ret : %d\n", ret);
    } else {
      printf("write successful! ret %d,buf:%d &buf:%p\n", ret, buf, &buf);
    }
    buf = ~buf;
    sleep(2);
  }
failed:
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11ad <main+0x5d>
lea    0xe7b(%rip),%rdi
mov    $0x1c,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125a <main+0x10a>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1246 <main+0xf6>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    120d <main+0xbd>
mov    -0xc(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1225 <main+0xd5>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe23(%rip),%rdi
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d0 <main+0x80>
jmp    124b <main+0xfb>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a8 <main+0x58>
mov    %eax,%ebx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %eax,%eax
js     11c0 <main+0x70>
mov    0xc(%rsp),%edx
lea    0xea5(%rip),%rdi
lea    0xc(%rsp),%rcx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d0 <main+0x80>
lea    0xe61(%rip),%rdi
mov    $0x1c,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    131d <main+0x1cd>
lea    0xe5e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
notl   0xc(%rsp)
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %eax,%eax
js     120e <main+0xbe>
mov    0xc(%rsp),%edx
lea    0xe3f(%rip),%rdi
lea    0xc(%rsp),%rcx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    121e <main+0xce>
lea    0xe10(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
notl   0xc(%rsp)
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %eax,%eax
js     125c <main+0x10c>
mov    0xc(%rsp),%edx
lea    0xdf1(%rip),%rdi
lea    0xc(%rsp),%rcx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    126c <main+0x11c>
lea    0xdc2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
notl   0xc(%rsp)
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %eax,%eax
js     12aa <main+0x15a>
mov    0xc(%rsp),%edx
lea    0xda3(%rip),%rdi
lea    0xc(%rsp),%rcx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12ba <main+0x16a>
lea    0xd74(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
notl   0xc(%rsp)
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
test   %eax,%eax
js     12f8 <main+0x1a8>
mov    0xc(%rsp),%edx
lea    0xd55(%rip),%rdi
lea    0xc(%rsp),%rcx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1308 <main+0x1b8>
lea    0xd26(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
notl   0xc(%rsp)
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/led_by_EOF\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"line %d open failed\0A\00"
@.str.2 = [24 x i8] c"write error!\0A ret : %d\0A\00"
@.str.3 = [41 x i8] c"write successful! ret %d,buf:%d &buf:%p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 28)
store i32 0, i32* %1
br label %37
11: ; preds = %0
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %4
br label %12
12: ; preds = %30, %11
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 5
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = load i32, i32* %2
%17 = call i32 @write(i32 %16, i32* %4, i32 4)
store i32 %17, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %26
22: ; preds = %15
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %24, i32* %4)
br label %26
26: ; preds = %22, %19
%27 = load i32, i32* %4
%28 = xor i32 %27, -1
store i32 %28, i32* %4
%29 = call i32 @sleep(i32 2)
br label %30
30: ; preds = %26
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %12
33: ; preds = %12
br label %34
34: ; preds = %33
%35 = load i32, i32* %2
%36 = call i32 @close(i32 %35)
store i32 0, i32* %1
br label %37
37: ; preds = %34, %9
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/led_by_EOF\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"line %d open failed\0A\00"
@.str.2 = [24 x i8] c"write error!\0A ret : %d\0A\00"
@.str.3 = [41 x i8] c"write successful! ret %d,buf:%d &buf:%p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 28)
br label %65
7: ; preds = %0
%8 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%9 = call i32 @write(i32 %3, i32* %1, i32 4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %16
13: ; preds = %7
%14 = load i32, i32* %1
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 %14, i32* %1)
br label %16
16: ; preds = %13, %11
%17 = load i32, i32* %1
%18 = xor i32 %17, -1
store i32 %18, i32* %1
%19 = call i32 @sleep(i32 2)
%20 = call i32 @write(i32 %3, i32* %1, i32 4)
%21 = icmp slt i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = load i32, i32* %1
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %23, i32* %1)
br label %27
25: ; preds = %16
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %1
%29 = xor i32 %28, -1
store i32 %29, i32* %1
%30 = call i32 @sleep(i32 2)
%31 = call i32 @write(i32 %3, i32* %1, i32 4)
%32 = icmp slt i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %27
%34 = load i32, i32* %1
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %34, i32* %1)
br label %38
36: ; preds = %27
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %38
38: ; preds = %36, %33
%39 = load i32, i32* %1
%40 = xor i32 %39, -1
store i32 %40, i32* %1
%41 = call i32 @sleep(i32 2)
%42 = call i32 @write(i32 %3, i32* %1, i32 4)
%43 = icmp slt i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %38
%45 = load i32, i32* %1
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %45, i32* %1)
br label %49
47: ; preds = %38
%48 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %49
49: ; preds = %47, %44
%50 = load i32, i32* %1
%51 = xor i32 %50, -1
store i32 %51, i32* %1
%52 = call i32 @sleep(i32 2)
%53 = call i32 @write(i32 %3, i32* %1, i32 4)
%54 = icmp slt i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %49
%56 = load i32, i32* %1
%57 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %53, i32 %56, i32* %1)
br label %60
58: ; preds = %49
%59 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %53)
br label %60
60: ; preds = %58, %55
%61 = load i32, i32* %1
%62 = xor i32 %61, -1
store i32 %62, i32* %1
%63 = call i32 @sleep(i32 2)
%64 = call i32 @close(i32 %3)
br label %65
65: ; preds = %60, %5
ret i32 0
}