#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 /*<<< orphan*/ buf;

/* Variables and functions */
int O_EXCL;
int O_RDWR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fsync_all(int);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write_all(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char buf[256] = "How you doing? dude";
  fd = open("test.log", O_RDWR | O_EXCL, 0644);
  write_all(fd, buf, sizeof(buf));
  if (fsync_all(fd) == -1)
    fprintf(stderr, "fsync_all() failed!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x100,%edx
call   1040 <memcpy@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    0x2e3f(%rip),%rax
or     (%rax),%esi
lea    0xf66(%rip),%rdi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1050 <write_all@plt>
mov    -0x14(%rbp),%edi
call   1060 <fsync_all@plt>
cmp    $0xffffffff,%eax
jne    11e1 <main+0x91>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xf2d(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
lea    0xea0(%rip),%rsi
mov    %rsp,%rbx
mov    $0x100,%edx
mov    %rbx,%rdi
call   1040 <memcpy@plt>
mov    0x2e71(%rip),%rax
mov    0x2e52(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xf77(%rip),%rdi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <write_all@plt>
mov    %ebp,%edi
call   1060 <fsync_all@plt>
cmp    $0xffffffff,%eax
jne    11c5 <main+0x75>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xf49(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.buf = [256 x i8] c"How you doing? dude\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [9 x i8] c"test.log\00"
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"fsync_all() failed!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [256 x i8]* %7 to i8*
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_EXCL
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11, i32 420)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%15 = call i32 @write_all(i32 %13, i8* %14, i32 256)
%16 = load i32, i32* %6
%17 = call i32 @fsync_all(i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %2
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf = [256 x i8] c"How you doing? dude\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [9 x i8] c"test.log\00"
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"fsync_all() failed!\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_EXCL
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7, i32 420)
%9 = call i32 @write_all(i32 %8, i8* %4, i32 256)
%10 = call i32 @fsync_all(i32 %8)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %2
ret i32 0
}