#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*/ t;
typedef int ssize_t;
typedef int int64_t;

/* Variables and functions */
int BUFSIZ;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memcpy(char *, int *, int);
int /*<<< orphan*/ memset(char *, int, int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main() {
  int fd = open("test.data", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
  char buf[BUFSIZ];
  memset(buf, 0x00, BUFSIZ);
  int64_t t = 4000000;
  memcpy(buf, &t, sizeof(t));
  ssize_t s = write(fd, buf, BUFSIZ);
  if (s != BUFSIZ) {
    fprintf(stderr, "write error, s=%ld", s);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
or     %eax,%esi
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
or     %eax,%esi
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
lea    0xe62(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
movl   $0x3d0900,-0x1c(%rbp)
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2da3(%rip),%rcx
cmp    (%rcx),%eax
je     123d <main+0xdd>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xdd2(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e3f(%rip),%rax
mov    0x2e80(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6d(%rip),%rax
or     (%rax),%esi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
lea    0xe6b(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r14d
mov    0x2e1c(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x3d0900,-0x1c(%rbp)
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    (%r15),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
cmp    (%r15),%eax
je     1207 <main+0xa7>
mov    0x2dd1(%rip),%rcx
mov    (%rcx),%edi
lea    0xe0a(%rip),%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"test.data\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"write error, s=%ld\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRWXU
%13 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
store i32 %13, i32* %2
%14 = load i32, i32* @BUFSIZ
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %3
%17 = alloca i8, i64 %15
store i64 %15, i64* %4
%18 = load i32, i32* @BUFSIZ
%19 = call i32 @memset(i8* %17, i32 0, i32 %18)
store i32 4000000, i32* %5
%20 = call i32 @memcpy(i8* %17, i32* %5, i32 4)
%21 = load i32, i32* %2
%22 = load i32, i32* @BUFSIZ
%23 = call i32 @write(i32 %21, i8* %17, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = load i32, i32* @BUFSIZ
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %0
%28 = load i32, i32* @stderr
%29 = load i32, i32* %6
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %27, %0
%32 = load i32, i32* %2
%33 = call i32 @close(i32 %32)
store i32 0, i32* %1
%34 = load i8*, i8** %3
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [10 x i8] c"test.data\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"write error, s=%ld\00"
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IRWXU
%8 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = call i32 @memset(i8* %11, i32 0, i32 %9)
%13 = bitcast i32* %1 to i8*
store i32 4000000, i32* %1
%14 = call i32 @memcpy(i8* %11, i32* %1, i32 4)
%15 = load i32, i32* @BUFSIZ
%16 = call i32 @write(i32 %8, i8* %11, i32 %15)
%17 = load i32, i32* @BUFSIZ
%18 = icmp eq i32 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %0
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %22
22: ; preds = %19, %0
%23 = call i32 @close(i32 %8)
ret i32 0
}