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

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char *argv[]) {
  int outfd;
  uint16_t i;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <out>\n", argv[0]);
    exit(1);
  }
  outfd =
      open(argv[1], O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
  if (-1 == outfd) {
    perror("open");
    exit(1);
  }
  for (i = 0; i < 500; i++) {
    write(outfd, &i, sizeof(i));
  }
  close(outfd);
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
je     11a6 <main+0x46>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    0x2e3a(%rip),%rax
or     (%rax),%esi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    0x2de8(%rip),%rax
or     (%rax),%edx
mov    0x2def(%rip),%rax
or     (%rax),%edx
mov    0x2dde(%rip),%rax
or     (%rax),%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1210 <main+0xb0>
lea    0xe10(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x1f4,-0x18(%rbp)
jge    1243 <main+0xe3>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1217 <main+0xb7>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1200 <main+0xa0>
mov    0x2e30(%rip),%rcx
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2e56(%rip),%rcx
mov    0x2e27(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e2c(%rip),%rcx
or     (%rcx),%edx
mov    0x8(%rsi),%rdi
mov    0x2e17(%rip),%rcx
or     (%rcx),%edx
mov    %eax,%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1222 <main+0xc2>
mov    %eax,%ebx
movl   $0x0,0xc(%rsp)
mov    $0x1,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebp,0xc(%rsp)
add    $0x1,%ebp
cmp    $0x1f5,%ebp
jne    11d0 <main+0x70>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xded(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xde8(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Usage: %s <out>\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [5 x i8] c"open\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_WRONLY
%22 = load i32, i32* @O_CREAT
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IWUSR
%25 = load i32, i32* @S_IRUSR
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IRGRP
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IROTH
%30 = or i32 %28, %29
%31 = call i32 @open(i8* %20, i32 %23, i32 %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp eq i32 -1, %32
br i1 %33, label %34, label %37
34: ; preds = %17
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %17
store i32 0, i32* %7
br label %38
38: ; preds = %44, %37
%39 = load i32, i32* %7
%40 = icmp slt i32 %39, 500
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i32, i32* %6
%43 = call i32 @write(i32 %42, i32* %7, i32 4)
br label %44
44: ; preds = %41
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %38
47: ; preds = %38
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Usage: %s <out>\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [5 x i8] c"open\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %15, %14
%17 = load i32, i32* @S_IWUSR
%18 = load i32, i32* @S_IRUSR
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IRGRP
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IROTH
%23 = or i32 %21, %22
%24 = tail call i32 @open(i8* %13, i32 %16, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %27, label %26
26: ; preds = %11
store i32 0, i32* %3
br label %30
27: ; preds = %11
%28 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %26, %30
%31 = phi i32 [ 0, %26 ], [ %33, %30 ]
%32 = call i32 @write(i32 %24, i32* %3, i32 4)
%33 = add nuw nsw i32 %31, 1
store i32 %33, i32* %3
%34 = icmp eq i32 %33, 500
br i1 %34, label %35, label %30
35: ; preds = %30
%36 = tail call i32 @close(i32 %24)
ret i32 0
}