#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 O_CREAT;
int O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main() {
  int fd1, fd2, i, j;
  fd1 = open("testfile.bin", O_RDWR | O_CREAT, 0550);
  for (j = 0; j < 10; ++j) {
    for (i = '!'; i <= '}'; ++i) {
      unsigned char ch = i;
      write(fd1, &ch, 1);
    }
  }
  close(fd1);
  fd2 = open("testfile2.bin", O_RDWR | O_CREAT, 0550);
  for (i = 0; i < 256; ++i) {
    unsigned char ch = i;
    write(fd2, &ch, 1);
  }
  for (i = 0; i < 256; ++i) {
    unsigned char ch = 255 - i;
    write(fd2, &ch, 1);
  }
  for (i = 0; i < 256; ++i) {
    unsigned char ch = i;
    write(fd2, &ch, 1);
  }
  for (i = 0; i < 256; ++i) {
    unsigned char ch = 255 - i;
    write(fd2, &ch, 1);
  }
  close(fd2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
mov    0x2ea9(%rip),%rax
or     (%rax),%esi
lea    0xea8(%rip),%rdi
mov    $0x168,%edx
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11bf <main+0x8f>
movl   $0x21,-0x10(%rbp)
cmpl   $0x7d,-0x10(%rbp)
jg     11ac <main+0x7c>
mov    -0x10(%rbp),%eax
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117d <main+0x4d>
jmp    11b1 <main+0x81>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116c <main+0x3c>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
lea    0xe2d(%rip),%rdi
mov    $0x168,%edx
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x100,-0x10(%rbp)
jge    1226 <main+0xf6>
mov    -0x10(%rbp),%eax
mov    %al,-0x16(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f4 <main+0xc4>
movl   $0x0,-0x10(%rbp)
cmpl   $0x100,-0x10(%rbp)
jge    1264 <main+0x134>
mov    $0xff,%eax
sub    -0x10(%rbp),%eax
mov    %al,-0x17(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x17(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122d <main+0xfd>
movl   $0x0,-0x10(%rbp)
cmpl   $0x100,-0x10(%rbp)
jge    129d <main+0x16d>
mov    -0x10(%rbp),%eax
mov    %al,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    126b <main+0x13b>
movl   $0x0,-0x10(%rbp)
cmpl   $0x100,-0x10(%rbp)
jge    12db <main+0x1ab>
mov    $0xff,%eax
sub    -0x10(%rbp),%eax
mov    %al,-0x19(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12a4 <main+0x174>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e9d(%rip),%r15
mov    0x2eae(%rip),%r12
mov    (%r12),%esi
or     (%r15),%esi
lea    0xea8(%rip),%rdi
mov    $0x168,%edx
call   1050 <open@plt>
mov    %eax,%ebp
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    1170 <main+0x40>
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    11a0 <main+0x70>
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    11d0 <main+0xa0>
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    1200 <main+0xd0>
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    1230 <main+0x100>
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    1260 <main+0x130>
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    1290 <main+0x160>
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    12c0 <main+0x190>
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    12f0 <main+0x1c0>
mov    $0xffffffa3,%ebx
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x7e(%rbx),%eax
mov    %al,0xb(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
inc    %ebx
jne    1320 <main+0x1f0>
mov    %ebp,%edi
call   1040 <close@plt>
mov    (%r12),%esi
or     (%r15),%esi
lea    0xcbe(%rip),%rdi
mov    $0x168,%edx
call   1050 <open@plt>
mov    %eax,%ebx
xor    %ebp,%ebp
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %bpl,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
jne    1370 <main+0x240>
mov    $0x100,%ebp
lea    0xe(%rsp),%r14
nopl   0x0(%rax)
add    $0xffffffff,%ebp
mov    %bpl,0xe(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
test   %ebp,%ebp
jne    13a0 <main+0x270>
xor    %ebp,%ebp
lea    0xd(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %bpl,0xd(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
jne    13d0 <main+0x2a0>
mov    $0x100,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
add    $0xffffffff,%ebp
mov    %bpl,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
test   %ebp,%ebp
jne    1400 <main+0x2d0>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"testfile.bin\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [14 x i8] c"testfile2.bin\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
store i32 0, i32* %1
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_CREAT
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %13, i32 360)
store i32 %14, i32* %2
store i32 0, i32* %5
br label %15
15: ; preds = %31, %0
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 10
br i1 %17, label %18, label %34
18: ; preds = %15
store i32 33, i32* %4
br label %19
19: ; preds = %27, %18
%20 = load i32, i32* %4
%21 = icmp sle i32 %20, 125
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i32, i32* %4
%24 = trunc i32 %23 to i8
store i8 %24, i8* %6
%25 = load i32, i32* %2
%26 = call i32 @write(i32 %25, i8* %6, i32 1)
br label %27
27: ; preds = %22
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %19
30: ; preds = %19
br label %31
31: ; preds = %30
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %15
34: ; preds = %15
%35 = load i32, i32* %2
%36 = call i32 @close(i32 %35)
%37 = load i32, i32* @O_RDWR
%38 = load i32, i32* @O_CREAT
%39 = or i32 %37, %38
%40 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 360)
store i32 %40, i32* %3
store i32 0, i32* %4
br label %41
41: ; preds = %49, %34
%42 = load i32, i32* %4
%43 = icmp slt i32 %42, 256
br i1 %43, label %44, label %52
44: ; preds = %41
%45 = load i32, i32* %4
%46 = trunc i32 %45 to i8
store i8 %46, i8* %7
%47 = load i32, i32* %3
%48 = call i32 @write(i32 %47, i8* %7, i32 1)
br label %49
49: ; preds = %44
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %41
52: ; preds = %41
store i32 0, i32* %4
br label %53
53: ; preds = %62, %52
%54 = load i32, i32* %4
%55 = icmp slt i32 %54, 256
br i1 %55, label %56, label %65
56: ; preds = %53
%57 = load i32, i32* %4
%58 = sub nsw i32 255, %57
%59 = trunc i32 %58 to i8
store i8 %59, i8* %8
%60 = load i32, i32* %3
%61 = call i32 @write(i32 %60, i8* %8, i32 1)
br label %62
62: ; preds = %56
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
store i32 %64, i32* %4
br label %53
65: ; preds = %53
store i32 0, i32* %4
br label %66
66: ; preds = %74, %65
%67 = load i32, i32* %4
%68 = icmp slt i32 %67, 256
br i1 %68, label %69, label %77
69: ; preds = %66
%70 = load i32, i32* %4
%71 = trunc i32 %70 to i8
store i8 %71, i8* %9
%72 = load i32, i32* %3
%73 = call i32 @write(i32 %72, i8* %9, i32 1)
br label %74
74: ; preds = %69
%75 = load i32, i32* %4
%76 = add nsw i32 %75, 1
store i32 %76, i32* %4
br label %66
77: ; preds = %66
store i32 0, i32* %4
br label %78
78: ; preds = %87, %77
%79 = load i32, i32* %4
%80 = icmp slt i32 %79, 256
br i1 %80, label %81, label %90
81: ; preds = %78
%82 = load i32, i32* %4
%83 = sub nsw i32 255, %82
%84 = trunc i32 %83 to i8
store i8 %84, i8* %10
%85 = load i32, i32* %3
%86 = call i32 @write(i32 %85, i8* %10, i32 1)
br label %87
87: ; preds = %81
%88 = load i32, i32* %4
%89 = add nsw i32 %88, 1
store i32 %89, i32* %4
br label %78
90: ; preds = %78
%91 = load i32, i32* %3
%92 = call i32 @close(i32 %91)
%93 = load i32, i32* %1
ret i32 %93
}

LLVM IR (-O2):
@.str = [13 x i8] c"testfile.bin\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [14 x i8] c"testfile2.bin\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8, i32 360)
br label %10
10: ; preds = %0, %10
%11 = phi i32 [ 33, %0 ], [ %14, %10 ]
%12 = trunc i32 %11 to i8
store i8 %12, i8* %1
%13 = call i32 @write(i32 %9, i8* %1, i32 1)
%14 = add nuw nsw i32 %11, 1
%15 = icmp eq i32 %14, 126
br i1 %15, label %16, label %10
16: ; preds = %10, %16
%17 = phi i32 [ %20, %16 ], [ 33, %10 ]
%18 = trunc i32 %17 to i8
store i8 %18, i8* %1
%19 = call i32 @write(i32 %9, i8* %1, i32 1)
%20 = add nuw nsw i32 %17, 1
%21 = icmp eq i32 %20, 126
br i1 %21, label %22, label %16
22: ; preds = %16, %22
%23 = phi i32 [ %26, %22 ], [ 33, %16 ]
%24 = trunc i32 %23 to i8
store i8 %24, i8* %1
%25 = call i32 @write(i32 %9, i8* %1, i32 1)
%26 = add nuw nsw i32 %23, 1
%27 = icmp eq i32 %26, 126
br i1 %27, label %28, label %22
28: ; preds = %22, %28
%29 = phi i32 [ %32, %28 ], [ 33, %22 ]
%30 = trunc i32 %29 to i8
store i8 %30, i8* %1
%31 = call i32 @write(i32 %9, i8* %1, i32 1)
%32 = add nuw nsw i32 %29, 1
%33 = icmp eq i32 %32, 126
br i1 %33, label %34, label %28
34: ; preds = %28, %34
%35 = phi i32 [ %38, %34 ], [ 33, %28 ]
%36 = trunc i32 %35 to i8
store i8 %36, i8* %1
%37 = call i32 @write(i32 %9, i8* %1, i32 1)
%38 = add nuw nsw i32 %35, 1
%39 = icmp eq i32 %38, 126
br i1 %39, label %40, label %34
40: ; preds = %34, %40
%41 = phi i32 [ %44, %40 ], [ 33, %34 ]
%42 = trunc i32 %41 to i8
store i8 %42, i8* %1
%43 = call i32 @write(i32 %9, i8* %1, i32 1)
%44 = add nuw nsw i32 %41, 1
%45 = icmp eq i32 %44, 126
br i1 %45, label %46, label %40
46: ; preds = %40, %46
%47 = phi i32 [ %50, %46 ], [ 33, %40 ]
%48 = trunc i32 %47 to i8
store i8 %48, i8* %1
%49 = call i32 @write(i32 %9, i8* %1, i32 1)
%50 = add nuw nsw i32 %47, 1
%51 = icmp eq i32 %50, 126
br i1 %51, label %52, label %46
52: ; preds = %46, %52
%53 = phi i32 [ %56, %52 ], [ 33, %46 ]
%54 = trunc i32 %53 to i8
store i8 %54, i8* %1
%55 = call i32 @write(i32 %9, i8* %1, i32 1)
%56 = add nuw nsw i32 %53, 1
%57 = icmp eq i32 %56, 126
br i1 %57, label %58, label %52
58: ; preds = %52, %58
%59 = phi i32 [ %62, %58 ], [ 33, %52 ]
%60 = trunc i32 %59 to i8
store i8 %60, i8* %1
%61 = call i32 @write(i32 %9, i8* %1, i32 1)
%62 = add nuw nsw i32 %59, 1
%63 = icmp eq i32 %62, 126
br i1 %63, label %64, label %58
64: ; preds = %58, %64
%65 = phi i32 [ %68, %64 ], [ 33, %58 ]
%66 = trunc i32 %65 to i8
store i8 %66, i8* %1
%67 = call i32 @write(i32 %9, i8* %1, i32 1)
%68 = add nuw nsw i32 %65, 1
%69 = icmp eq i32 %68, 126
br i1 %69, label %70, label %64
70: ; preds = %64
%71 = tail call i32 @close(i32 %9)
%72 = load i32, i32* @O_RDWR
%73 = load i32, i32* @O_CREAT
%74 = or i32 %73, %72
%75 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %74, i32 360)
br label %76
76: ; preds = %70, %76
%77 = phi i32 [ 0, %70 ], [ %80, %76 ]
%78 = trunc i32 %77 to i8
store i8 %78, i8* %2
%79 = call i32 @write(i32 %75, i8* %2, i32 1)
%80 = add nuw nsw i32 %77, 1
%81 = icmp eq i32 %80, 256
br i1 %81, label %82, label %76
82: ; preds = %76, %82
%83 = phi i32 [ %87, %82 ], [ 0, %76 ]
%84 = trunc i32 %83 to i8
%85 = xor i8 %84, -1
store i8 %85, i8* %3
%86 = call i32 @write(i32 %75, i8* %3, i32 1)
%87 = add nuw nsw i32 %83, 1
%88 = icmp eq i32 %87, 256
br i1 %88, label %89, label %82
89: ; preds = %82, %89
%90 = phi i32 [ %93, %89 ], [ 0, %82 ]
%91 = trunc i32 %90 to i8
store i8 %91, i8* %4
%92 = call i32 @write(i32 %75, i8* %4, i32 1)
%93 = add nuw nsw i32 %90, 1
%94 = icmp eq i32 %93, 256
br i1 %94, label %95, label %89
95: ; preds = %89, %95
%96 = phi i32 [ %100, %95 ], [ 0, %89 ]
%97 = trunc i32 %96 to i8
%98 = xor i8 %97, -1
store i8 %98, i8* %5
%99 = call i32 @write(i32 %75, i8* %5, i32 1)
%100 = add nuw nsw i32 %96, 1
%101 = icmp eq i32 %100, 256
br i1 %101, label %102, label %95
102: ; preds = %95
%103 = tail call i32 @close(i32 %75)
ret i32 0
}