#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*/ errno;
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ pwrite(int, char *, int, int);
char *strerror(int /*<<< orphan*/);
int create_file(char *name, int size) {
  char c;
  int fd;
  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);
  return 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
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    0x2e95(%rip),%rax
or     (%rax),%esi
mov    $0x1a0,%edx
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11b1 <create_file+0x71>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <create_file+0x92>
movb   $0x0,-0x15(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1040 <pwrite@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
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,%ebx
mov    %rdi,%r14
mov    0x2e8c(%rip),%rax
mov    0x2e9d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a0,%edx
call   1050 <open@plt>
test   %eax,%eax
js     118c <create_file+0x4c>
mov    %eax,%ebp
movb   $0x0,0xf(%rsp)
add    $0xffffffff,%ebx
lea    0xf(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
mov    %ebx,%ecx
call   1040 <pwrite@plt>
jmp    11b1 <create_file+0x71>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe5f(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%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 = 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 416)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %18)
store i32 -1, i32* %3
br label %26
20: ; preds = %2
store i8 0, i8* %6
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = call i32 @pwrite(i32 %21, i8* %6, i32 1, i32 %23)
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %20, %15
%27 = load i32, i32* %3
ret i32 %27
}

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 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6, i32 416)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %11)
br label %16
13: ; preds = %2
store i8 0, i8* %3
%14 = add nsw i32 %1, -1
%15 = call i32 @pwrite(i32 %7, i8* %3, i32 1, i32 %14)
br label %16
16: ; preds = %13, %9
%17 = phi i32 [ -1, %9 ], [ %7, %13 ]
ret i32 %17
}