#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main() {
  do {
  } while (0);
  int i = 0;
  int i_ret = 0;
  int fd = 0;
  int all_count = 0;
  char buf[14000 + 10] = {0};
  fd = open("/dev/scull0", O_RDWR);
  if (-1 == fd) {
    do {
    } while (0);
  }
  for (i = 0; i < 1000; i++) {
    i_ret = write(fd, "this is a test", strlen("this is a test"));
    if (-1 == i_ret) {
      do {
      } while (0);
    }
    do {
    } while (0);
    all_count += i_ret;
  }
  i_ret = write(fd, "\n", strlen("\n"));
  if (-1 == i_ret) {
    do {
    } while (0);
  }
  do {
  } while (0);
  close(fd);
  fd = open("/dev/scull0", O_RDWR);
  if (-1 == fd) {
    do {
    } while (0);
  }
  while (all_count > 0) {
    i_ret = read(fd, buf, 14000);
    if (-1 == i_ret) {
      do {
      } while (0);
    }
    do {
    } while (0);
    all_count -= i_ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x36e0,%rsp
movl   $0x0,-0x4(%rbp)
jmp    1177 <main+0x17>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x36d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x36ba,%edx
call   1050 <memset@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe4a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
mov    $0xffffffff,%eax
cmp    -0x10(%rbp),%eax
jne    11db <main+0x7b>
jmp    11d1 <main+0x71>
jmp    11d6 <main+0x76>
jmp    11db <main+0x7b>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1259 <main+0xf9>
mov    -0x10(%rbp),%eax
mov    %eax,-0x36d4(%rbp)
lea    0xe0d(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x36d4(%rbp),%edi
mov    %eax,%edx
lea    0xdf9(%rip),%rsi
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    $0xffffffff,%eax
cmp    -0xc(%rbp),%eax
jne    1238 <main+0xd8>
jmp    122e <main+0xce>
jmp    1233 <main+0xd3>
jmp    1238 <main+0xd8>
jmp    123d <main+0xdd>
jmp    1242 <main+0xe2>
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e2 <main+0x82>
mov    -0x10(%rbp),%eax
mov    %eax,-0x36d8(%rbp)
lea    0xdb2(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x36d8(%rbp),%edi
mov    %eax,%edx
lea    0xd9e(%rip),%rsi
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    $0xffffffff,%eax
cmp    -0xc(%rbp),%eax
jne    12a2 <main+0x142>
jmp    1298 <main+0x138>
jmp    129d <main+0x13d>
jmp    12a2 <main+0x142>
jmp    12a7 <main+0x147>
jmp    12ac <main+0x14c>
mov    -0x10(%rbp),%edi
call   1060 <close@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
lea    0xd3c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
mov    $0xffffffff,%eax
cmp    -0x10(%rbp),%eax
jne    12e9 <main+0x189>
jmp    12df <main+0x17f>
jmp    12e4 <main+0x184>
jmp    12e9 <main+0x189>
jmp    12ee <main+0x18e>
cmpl   $0x0,-0x14(%rbp)
jle    1346 <main+0x1e6>
mov    -0x10(%rbp),%edi
lea    -0x36d0(%rbp),%rsi
mov    $0x36b0,%edx
call   1070 <read@plt>
mov    %eax,-0xc(%rbp)
mov    $0xffffffff,%eax
cmp    -0xc(%rbp),%eax
jne    132c <main+0x1cc>
jmp    1322 <main+0x1c2>
jmp    1327 <main+0x1c7>
jmp    132c <main+0x1cc>
jmp    1331 <main+0x1d1>
jmp    1336 <main+0x1d6>
mov    -0xc(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    12ee <main+0x18e>
xor    %eax,%eax
add    $0x36e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x36c0,%rsp
mov    %rsp,%rdi
xor    %ebp,%ebp
mov    $0x36ba,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2e61(%rip),%r15
mov    (%r15),%esi
lea    0xe6f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r14d
mov    $0x3e8,%ebx
lea    0xe67(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    %eax,%ebp
add    $0xffffffff,%ebx
jne    11b0 <main+0x50>
lea    0xe48(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    (%r15),%esi
lea    0xe06(%rip),%rdi
call   1080 <open@plt>
test   %ebp,%ebp
jle    1223 <main+0xc3>
mov    %eax,%ebx
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x36b0,%edx
call   1070 <read@plt>
sub    %eax,%ebp
jg     1210 <main+0xb0>
xor    %eax,%eax
add    $0x36c0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/scull0\00"
@O_RDWR = global i32 0
@.str.1 = [15 x i8] c"this is a test\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [14010 x i8]
store i32 0, i32* %1
br label %7
7: ; preds = %0
br label %8
8: ; preds = %7
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%9 = bitcast [14010 x i8]* %6 to i8*
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %17
14: ; preds = %8
br label %15
15: ; preds = %14
br label %16
16: ; preds = %15
br label %17
17: ; preds = %16, %8
store i32 0, i32* %2
br label %18
18: ; preds = %36, %17
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 1000
br i1 %20, label %21, label %39
21: ; preds = %18
%22 = load i32, i32* %4
%23 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @write(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp eq i32 -1, %25
br i1 %26, label %27, label %30
27: ; preds = %21
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29, %21
br label %31
31: ; preds = %30
br label %32
32: ; preds = %31
%33 = load i32, i32* %3
%34 = load i32, i32* %5
%35 = add nsw i32 %34, %33
store i32 %35, i32* %5
br label %36
36: ; preds = %32
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %18
39: ; preds = %18
%40 = load i32, i32* %4
%41 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @write(i32 %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %41)
store i32 %42, i32* %3
%43 = load i32, i32* %3
%44 = icmp eq i32 -1, %43
br i1 %44, label %45, label %48
45: ; preds = %39
br label %46
46: ; preds = %45
br label %47
47: ; preds = %46
br label %48
48: ; preds = %47, %39
br label %49
49: ; preds = %48
br label %50
50: ; preds = %49
%51 = load i32, i32* %4
%52 = call i32 @close(i32 %51)
%53 = load i32, i32* @O_RDWR
%54 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %53)
store i32 %54, i32* %4
%55 = load i32, i32* %4
%56 = icmp eq i32 -1, %55
br i1 %56, label %57, label %60
57: ; preds = %50
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
br label %60
60: ; preds = %59, %50
br label %61
61: ; preds = %75, %60
%62 = load i32, i32* %5
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %79
64: ; preds = %61
%65 = load i32, i32* %4
%66 = getelementptr inbounds [14010 x i8], [14010 x i8]* %6, i64 0, i64 0
%67 = call i32 @read(i32 %65, i8* %66, i32 14000)
store i32 %67, i32* %3
%68 = load i32, i32* %3
%69 = icmp eq i32 -1, %68
br i1 %69, label %70, label %73
70: ; preds = %64
br label %71
71: ; preds = %70
br label %72
72: ; preds = %71
br label %73
73: ; preds = %72, %64
br label %74
74: ; preds = %73
br label %75
75: ; preds = %74
%76 = load i32, i32* %3
%77 = load i32, i32* %5
%78 = sub nsw i32 %77, %76
store i32 %78, i32* %5
br label %61
79: ; preds = %61
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/scull0\00"
@O_RDWR = global i32 0
@.str.1 = [15 x i8] c"this is a test\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [14010 x i8]
%2 = getelementptr inbounds [14010 x i8], [14010 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 0, %0 ], [ %10, %5 ]
%7 = phi i32 [ 0, %0 ], [ %11, %5 ]
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = add nsw i32 %9, %6
%11 = add nuw nsw i32 %7, 1
%12 = icmp eq i32 %11, 1000
br i1 %12, label %13, label %5
13: ; preds = %5
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = tail call i32 @close(i32 %4)
%17 = load i32, i32* @O_RDWR
%18 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = icmp sgt i32 %10, 0
br i1 %19, label %20, label %25
20: ; preds = %13, %20
%21 = phi i32 [ %23, %20 ], [ %10, %13 ]
%22 = call i32 @read(i32 %18, i8* %2, i32 14000)
%23 = sub nsw i32 %21, %22
%24 = icmp sgt i32 %23, 0
br i1 %24, label %20, label %25
25: ; preds = %20, %13
ret i32 0
}