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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char **argv) {
  int fd = creat("/tmp/example.dat", 0777);
  if (fd < 0) {
    perror("unable to create file");
    return (1);
  }
  int value = 0x12345678;
  write(fd, &value, sizeof(value));
  close(fd);
  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)
lea    0xea3(%rip),%rdi
mov    $0x1ff,%esi
call   1060 <creat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118c <main+0x4c>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b3 <main+0x73>
movl   $0x12345678,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
mov    $0x1ff,%esi
call   1060 <creat@plt>
test   %eax,%eax
js     1184 <main+0x44>
mov    %eax,%ebx
movl   $0x12345678,0xc(%rsp)
12
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe86(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
jmp    117e <main+0x3e>

LLVM IR (-O0):
@.str = [17 x i8] c"/tmp/example.dat\00"
@.str.1 = [22 x i8] c"unable to create file\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 = call i32 @creat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 511)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %18
13: ; preds = %2
store i32 305419896, i32* %7
%14 = load i32, i32* %6
%15 = call i32 @write(i32 %14, i32* %7, i32 4)
%16 = load i32, i32* %6
%17 = call i32 @close(i32 %16)
store i32 0, i32* %3
br label %18
18: ; preds = %13, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [17 x i8] c"/tmp/example.dat\00"
@.str.1 = [22 x i8] c"unable to create file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 @creat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 511)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %12
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
store i32 305419896, i32* %3
%10 = call i32 @write(i32 %4, i32* %3, i32 4)
%11 = tail call i32 @close(i32 %4)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ 1, %6 ], [ 0, %8 ]
ret i32 %13
}