#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*/ __ploop_err(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
scalar_t__ fchmod(int, int);
int open(char *, int, int);
int create_file(char *fname) {
  int fd;
  fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0600);
  if (fd == -1) {
    __ploop_err(errno, "Can't create file %s", fname);
    return -1;
  }
  if (fchmod(fd, 0644))
    __ploop_err(errno, "Can't chmod(0644) on %s", fname);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    0x2e98(%rip),%rax
or     (%rax),%esi
mov    0x2e87(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a7 <create_file+0x67>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6a(%rip),%rsi
call   1060 <__ploop_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <create_file+0xa6>
mov    -0x14(%rbp),%edi
mov    $0x1a4,%esi
call   1040 <fchmod@plt>
cmp    $0x0,%rax
je     11d7 <create_file+0x97>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe43(%rip),%rsi
call   1060 <__ploop_err@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e76(%rip),%rax
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rdi,%rbx
mov    0x2e91(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11a6 <create_file+0x66>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1a4,%esi
call   1040 <fchmod@plt>
test   %rax,%rax
je     119b <create_file+0x5b>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rbx,%rdx
call   1060 <__ploop_err@plt>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
jmp    11c3 <create_file+0x83>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdx
call   1060 <__ploop_err@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@errno = global i32 0
@.str = [21 x i8] c"Can't create file %s\00"
@.str.1 = [24 x i8] c"Can't chmod(0644) on %s\00"
define i32 @create_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = call i32 @open(i8* %5, i32 %10, i32 384)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @errno
%16 = load i8*, i8** %3
%17 = call i32 @__ploop_err(i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %2
br label %29
18: ; preds = %1
%19 = load i32, i32* %4
%20 = call i64 @fchmod(i32 %19, i32 420)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* @errno
%24 = load i8*, i8** %3
%25 = call i32 @__ploop_err(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %18
%27 = load i32, i32* %4
%28 = call i32 @close(i32 %27)
store i32 0, i32* %2
br label %29
29: ; preds = %26, %14
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@errno = global i32 0
@.str = [21 x i8] c"Can't create file %s\00"
@.str.1 = [24 x i8] c"Can't chmod(0644) on %s\00"
define i32 @create_file(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = tail call i32 @open(i8* %0, i32 %6, i32 384)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = tail call i32 @__ploop_err(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %20
12: ; preds = %1
%13 = tail call i64 @fchmod(i32 %7, i32 420)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* @errno
%17 = tail call i32 @__ploop_err(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %15, %12
%19 = tail call i32 @close(i32 %7)
br label %20
20: ; preds = %18, %9
%21 = phi i32 [ -1, %9 ], [ 0, %18 ]
ret i32 %21
}