#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 ssize_t;
typedef int off_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
int write(int, ...);
int create_empty_file(char *file) {
  int fd = 0;
  ssize_t ret;
  fd = open(file, O_RDWR | O_CREAT, 0600);
  if (fd == -1)
    return fd;
  char header[10] = {0x23, 0x40, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
  ret = write(fd, &header, 10);
  if (ret == -1)
    return -1;
  off_t offset = lseek(fd, (off_t)20, SEEK_SET);
  if (offset == -1)
    return -1;
  ret = write(fd, "|\0", 2);
  if (ret == -1)
    return -1;
  return fd;
}


x86 assembly (clang, -O0):
<create_empty_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    0x2ea1(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117b <create_empty_file+0x4b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1221 <create_empty_file+0xf1>
mov    0xe7e(%rip),%rax
mov    %rax,-0x22(%rbp)
mov    0xe7b(%rip),%ax
mov    %ax,-0x1a(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0xa,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11bd <create_empty_file+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <create_empty_file+0xf1>
mov    -0x14(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1040 <lseek@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11ec <create_empty_file+0xbc>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <create_empty_file+0xf1>
mov    -0x14(%rbp),%edi
lea    0xe14(%rip),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    121b <create_empty_file+0xeb>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <create_empty_file+0xf1>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_empty_file>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2ea3(%rip),%rax
mov    0x2eb4(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11bf <create_empty_file+0x8f>
mov    %eax,%ebx
movw   $0x0,0x10(%rsp)
movq   $0x304023,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0xa,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11c4 <create_empty_file+0x94>
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x14,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     11c4 <create_empty_file+0x94>
lea    0xe63(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
cmove  %eax,%ebx
mov    %ebx,%ebp
jmp    11c4 <create_empty_file+0x94>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@__const.create_empty_file.header = [10 x i8] c"#@0\00\00\00\00\00\00\00"
@SEEK_SET = global i32 0
@.str = [3 x i8] c"|\00\00"
define i32 @create_empty_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %8, i32 %11, i32 384)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %39
17: ; preds = %1
%18 = bitcast [10 x i8]* %6 to i8*
%19 = load i32, i32* %4
%20 = call i32 (i32, ...) @write(i32 %19, [10 x i8]* %6, i32 10)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 -1, i32* %2
br label %39
24: ; preds = %17
%25 = load i32, i32* %4
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @lseek(i32 %25, i32 20, i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 -1, i32* %2
br label %39
31: ; preds = %24
%32 = load i32, i32* %4
%33 = call i32 (i32, ...) @write(i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 -1, i32* %2
br label %39
37: ; preds = %31
%38 = load i32, i32* %4
store i32 %38, i32* %2
br label %39
39: ; preds = %37, %36, %30, %23, %15
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@__const.create_empty_file.header = [10 x i8] c"#@0\00\00\00\00\00\00\00"
@SEEK_SET = global i32 0
@.str = [3 x i8] c"|\00\00"
define i32 @create_empty_file(i8* nocapture %0) {
%2 = alloca [10 x i8]
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* %0, i32 %5, i32 384)
%7 = icmp eq i32 %6, -1
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%10 = call i32 (i32, ...) @write(i32 %6, [10 x i8]* %2, i32 10)
%11 = icmp eq i32 %10, -1
br i1 %11, label %20, label %12
12: ; preds = %8
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @lseek(i32 %6, i32 20, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = call i32 (i32, ...) @write(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%18 = icmp eq i32 %17, -1
%19 = select i1 %18, i32 -1, i32 %6
br label %20
20: ; preds = %12, %16, %8
%21 = phi i32 [ -1, %8 ], [ -1, %12 ], [ %19, %16 ]
br label %22
22: ; preds = %1, %20
%23 = phi i32 [ %21, %20 ], [ -1, %1 ]
ret i32 %23
}