#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_DSYNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
void *malloc(int);
int open(char *, int);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int write(int, void *, int);
int main(int argc, char **argv) {
  void *buf;
  int fd, i;
  if ((buf = malloc(1024 * 1024)) == NULL) {
    perror(NULL);
    exit(1);
  }
  if ((fd = open("data100m", O_CREAT | O_WRONLY | O_DSYNC)) == -1) {
    perror(NULL);
    exit(1);
  }
  for (;;) {
    for (i = 0; i != 100; i++) {
      if (write(fd, buf, 1024 * 1024) == -1) {
        perror(NULL);
        exit(1);
      }
    }
    if (lseek(fd, 0, SEEK_SET) == -1) {
      perror(NULL);
      exit(1);
    }
  }
  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)
mov    $0x100000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a1 <main+0x41>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    0x2e0f(%rip),%rax
or     (%rax),%esi
mov    0x2e1e(%rip),%rax
or     (%rax),%esi
lea    0xe3d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11e7 <main+0x87>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11ec <main+0x8c>
movl   $0x0,-0x20(%rbp)
cmpl   $0x64,-0x20(%rbp)
je     123d <main+0xdd>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x100000,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    122a <main+0xca>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    122f <main+0xcf>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11f3 <main+0x93>
mov    -0x1c(%rbp),%edi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    126c <main+0x10c>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11ec <main+0x8c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x100000,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11a5 <main+0x45>
mov    %rax,%r15
mov    0x2e78(%rip),%rax
mov    0x2e39(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e46(%rip),%rax
or     (%rax),%esi
lea    0xe65(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
jne    11b6 <main+0x56>
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    0x2e0f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x100000,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11a5 <main+0x45>
add    $0x1,%ebx
cmp    $0x64,%ebx
jne    11d0 <main+0x70>
mov    (%r14),%edx
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0x70>
jmp    11a5 <main+0x45>

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

LLVM IR (-O2):
@.str = [9 x i8] c"data100m\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_DSYNC = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i32* null)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_WRONLY
%11 = or i32 %10, %9
%12 = load i32, i32* @O_DSYNC
%13 = or i32 %11, %12
%14 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %8
%17 = tail call i32 @perror(i32* null)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %23
%20 = icmp eq i32 %27, 100
br i1 %20, label %31, label %21
21: ; preds = %19, %31
%22 = phi i32 [ %27, %19 ], [ 0, %31 ]
br label %23
23: ; preds = %8, %21
%24 = phi i32 [ %22, %21 ], [ 0, %8 ]
%25 = tail call i32 @write(i32 %14, i8* %3, i32 1048576)
%26 = icmp eq i32 %25, -1
%27 = add nuw nsw i32 %24, 1
br i1 %26, label %28, label %19
28: ; preds = %23
%29 = tail call i32 @perror(i32* null)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %19
%32 = load i32, i32* @SEEK_SET
%33 = tail call i32 @lseek(i32 %14, i32 0, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %21
35: ; preds = %31
%36 = tail call i32 @perror(i32* null)
%37 = tail call i32 @exit(i32 1)
unreachable
}