#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_SYNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ do_write(int, char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
void write_flushed_data() {
  int fd;
  char *buf;
  buf = malloc(1048576);
  strcpy(buf, "Large data buffer follows.\n");
  fd = open("flush.data", O_CREAT | O_WRONLY | O_SYNC, 0644);
  do_write(fd, buf, 1048576);
  close(fd);
  free(buf);
}


x86 assembly (clang, -O0):
<write_flushed_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x100000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1040 <strcpy@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    0x2e32(%rip),%rax
or     (%rax),%esi
mov    0x2e41(%rip),%rax
or     (%rax),%esi
lea    0xe74(%rip),%rdi
mov    $0x1a4,%edx
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x100000,%edx
call   1050 <do_write@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_flushed_data>:
push   %rbp
push   %rbx
push   %rax
mov    $0x100000,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe89(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    0x2e72(%rip),%rax
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e48(%rip),%rax
or     (%rax),%esi
lea    0xe7b(%rip),%rdi
mov    $0x1a4,%edx
call   1080 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x100000,%edx
call   1050 <do_write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Large data buffer follows.\0A\00"
@.str.1 = [11 x i8] c"flush.data\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_SYNC = global i32 0
define void @write_flushed_data() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i8* @malloc(i32 1048576)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_WRONLY
%8 = or i32 %6, %7
%9 = load i32, i32* @O_SYNC
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 420)
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = load i8*, i8** %2
%14 = call i32 @do_write(i32 %12, i8* %13, i32 1048576)
%15 = load i32, i32* %1
%16 = call i32 @close(i32 %15)
%17 = load i8*, i8** %2
%18 = call i32 @free(i8* %17)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"Large data buffer follows.\0A\00"
@.str.1 = [11 x i8] c"flush.data\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_SYNC = global i32 0
define void @write_flushed_data() {
%1 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%2 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_WRONLY
%5 = or i32 %4, %3
%6 = load i32, i32* @O_SYNC
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 420)
%9 = tail call i32 @do_write(i32 %8, i8* %1, i32 1048576)
%10 = tail call i32 @close(i32 %8)
%11 = tail call i32 @free(i8* %1)
ret void
}