#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ pwrite(int, char *, int, int);
int /*<<< orphan*/ set_flockp(char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int create_file(char *name, int size) {
  char c;
  int fd;
  unlink(name);
  fd = open(name, O_RDWR | O_CREAT, 0640);
  if (fd < 0) {
    printf("open(%s) %s\n", name, strerror(errno));
    return -1;
  }
  c = 0;
  pwrite(fd, &c, 1, size - 1);
  set_flockp(name);
  close(fd);
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    0x2e5c(%rip),%rax
or     (%rax),%esi
mov    $0x1a0,%edx
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ea <create_file+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <create_file+0xa6>
movb   $0x0,-0x15(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1060 <pwrite@plt>
mov    -0x10(%rbp),%rdi
call   1080 <set_flockp@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <unlink@plt>
mov    0x2e56(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1a0,%edx
call   1070 <open@plt>
test   %eax,%eax
js     11d6 <create_file+0x66>
mov    %eax,%ebp
movb   $0x0,0xf(%rsp)
add    $0xffffffff,%r14d
lea    0xf(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
mov    %r14d,%ecx
call   1060 <pwrite@plt>
mov    %rbx,%rdi
call   1080 <set_flockp@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11f6 <create_file+0x86>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe15(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [13 x i8] c"open(%s) %s\0A\00"
@errno = global i32 0
define i32 @create_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = call i32 @unlink(i8* %8)
%10 = load i8*, i8** %4
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_CREAT
%13 = or i32 %11, %12
%14 = call i32 @open(i8* %10, i32 %13, i32 416)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %20)
store i32 -1, i32* %3
br label %31
22: ; preds = %2
store i8 0, i8* %6
%23 = load i32, i32* %7
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = call i32 @pwrite(i32 %23, i8* %6, i32 1, i32 %25)
%27 = load i8*, i8** %4
%28 = call i32 @set_flockp(i8* %27)
%29 = load i32, i32* %7
%30 = call i32 @close(i32 %29)
br label %31
31: ; preds = %22, %17
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [13 x i8] c"open(%s) %s\0A\00"
@errno = global i32 0
define i32 @create_file(i8* %0, i32 %1) {
%3 = alloca i8
%4 = tail call i32 @unlink(i8* %0)
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %0, i32 %7, i32 416)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %12)
br label %19
14: ; preds = %2
store i8 0, i8* %3
%15 = add nsw i32 %1, -1
%16 = call i32 @pwrite(i32 %8, i8* %3, i32 1, i32 %15)
%17 = tail call i32 @set_flockp(i8* %0)
%18 = tail call i32 @close(i32 %8)
br label %19
19: ; preds = %14, %10
ret i32 -1
}