#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_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned long lseek(int, unsigned long, int /*<<< orphan*/);
int open(char const *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int create_file(const char *filename, unsigned long int size_byte) {
  int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644);
  if (fd < 0) {
    fprintf(stderr, "open() failed: %s\n", strerror(errno));
    return 2;
  }
  --size_byte;
  if (lseek(fd, size_byte, SEEK_SET) != size_byte) {
    fprintf(stderr, "lseek() failed: %s\n", strerror(errno));
    close(fd);
    return 2;
  }
  switch (write(fd, "\0", 1)) {
  case -1:
    fprintf(stderr, "write() failed: %s\n", strerror(errno));
    close(fd);
    return 2;
  case 0:
    fprintf(stderr, "write() failed writing one byte, returning 0\n");
    close(fd);
    return 2;
  case 1:
    close(fd);
    return 0;
  default:
    fprintf(stderr, "write() returned unexpected value\n");
    close(fd);
    return 3;
  }
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
mov    0x2e6b(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e0 <create_file+0x80>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    133c <create_file+0x1dc>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    -0x18(%rbp),%rax
je     124d <create_file+0xed>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x2,-0x4(%rbp)
jmp    133c <create_file+0x1dc>
mov    -0x1c(%rbp),%edi
lea    0xe35(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
sub    $0xffffffff,%eax
je     1295 <create_file+0x135>
jmp    1274 <create_file+0x114>
mov    -0x28(%rbp),%eax
test   %eax,%eax
je     12d7 <create_file+0x177>
jmp    1284 <create_file+0x124>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
je     1302 <create_file+0x1a2>
jmp    1316 <create_file+0x1b6>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x2,-0x4(%rbp)
jmp    133c <create_file+0x1dc>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x2,-0x4(%rbp)
jmp    133c <create_file+0x1dc>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    133c <create_file+0x1dc>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e46(%rip),%rcx
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %rsi,%rbx
mov    0x2e79(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
test   %eax,%eax
js     11fc <create_file+0x9c>
mov    %eax,%ebp
add    $0xffffffffffffffff,%rbx
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <lseek@plt>
cmp    %rbx,%rax
jne    1228 <create_file+0xc8>
lea    0xed6(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1265 <create_file+0x105>
test   %eax,%eax
je     1270 <create_file+0x110>
cmp    $0xffffffff,%eax
jne    1289 <create_file+0x129>
mov    0x2ded(%rip),%rax
mov    (%rax),%ebx
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe2d(%rip),%rsi
jmp    1246 <create_file+0xe6>
mov    0x2dcd(%rip),%rax
mov    (%rax),%ebx
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xde6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1259 <create_file+0xf9>
mov    0x2da1(%rip),%rax
mov    (%rax),%ebx
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdcd(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    125e <create_file+0xfe>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1252 <create_file+0xf2>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    $0x3,%eax
jmp    125e <create_file+0xfe>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"open() failed: %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [20 x i8] c"lseek() failed: %s\0A\00"
@.str.2 = [2 x i8] zeroinitializer
@.str.3 = [20 x i8] c"write() failed: %s\0A\00"
@.str.4 = [46 x i8] c"write() failed writing one byte, returning 0\0A\00"
@.str.5 = [35 x i8] c"write() returned unexpected value\0A\00"
define i32 @create_file(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %7, i32 %12, i32 420)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 2, i32* %3
br label %60
21: ; preds = %2
%22 = load i64, i64* %5
%23 = add i64 %22, -1
store i64 %23, i64* %5
%24 = load i32, i32* %6
%25 = load i64, i64* %5
%26 = load i32, i32* @SEEK_SET
%27 = call i64 @lseek(i32 %24, i64 %25, i32 %26)
%28 = load i64, i64* %5
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %37
30: ; preds = %21
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %6
%36 = call i32 @close(i32 %35)
store i32 2, i32* %3
br label %60
37: ; preds = %21
%38 = load i32, i32* %6
%39 = call i32 @write(i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
switch i32 %39, label %55 [
i32 -1, label %40
i32 0, label %47
i32 1, label %52
]
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %43)
%45 = load i32, i32* %6
%46 = call i32 @close(i32 %45)
store i32 2, i32* %3
br label %60
47: ; preds = %37
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
store i32 2, i32* %3
br label %60
52: ; preds = %37
%53 = load i32, i32* %6
%54 = call i32 @close(i32 %53)
store i32 0, i32* %3
br label %60
55: ; preds = %37
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%58 = load i32, i32* %6
%59 = call i32 @close(i32 %58)
store i32 3, i32* %3
br label %60
60: ; preds = %55, %52, %47, %40, %30, %16
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"open() failed: %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [20 x i8] c"lseek() failed: %s\0A\00"
@.str.2 = [2 x i8] zeroinitializer
@.str.3 = [20 x i8] c"write() failed: %s\0A\00"
@.str.4 = [46 x i8] c"write() failed writing one byte, returning 0\0A\00"
@.str.5 = [35 x i8] c"write() returned unexpected value\0A\00"
define i32 @create_file(i8* nocapture %0, i64 %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_TRUNC
%5 = or i32 %4, %3
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* %0, i32 %7, i32 420)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %44
15: ; preds = %2
%16 = add i64 %1, -1
%17 = load i32, i32* @SEEK_SET
%18 = tail call i64 @lseek(i32 %8, i64 %16, i32 %17)
%19 = icmp eq i64 %18, %16
br i1 %19, label %26, label %20
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = tail call i32 @close(i32 %8)
br label %44
26: ; preds = %15
%27 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
switch i32 %27, label %40 [
i32 -1, label %28
i32 0, label %34
i32 1, label %38
]
28: ; preds = %26
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = tail call i32 @close(i32 %8)
br label %44
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%37 = tail call i32 @close(i32 %8)
br label %44
38: ; preds = %26
%39 = tail call i32 @close(i32 %8)
br label %44
40: ; preds = %26
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%43 = tail call i32 @close(i32 %8)
br label %44
44: ; preds = %40, %38, %34, %28, %20, %10
%45 = phi i32 [ 2, %10 ], [ 2, %20 ], [ 3, %40 ], [ 0, %38 ], [ 2, %34 ], [ 2, %28 ]
ret i32 %45
}