#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 mode_t;

/* Variables and functions */
int O_CREAT;
int O_EXCL;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int tftp_create(char *file, int *fd) {
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  if ((*fd = open(file, O_CREAT | O_EXCL, mode)) == -1) {
    printf("The file [%s] already exists !\n", file);
    return -1;
  }
  return (*fd);
}


x86 assembly (clang, -O0):
<tftp_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    0x2ea0(%rip),%rcx
or     (%rcx),%eax
mov    0x2e7f(%rip),%rcx
or     (%rcx),%eax
mov    0x2e6e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
or     (%rax),%esi
mov    -0x1c(%rbp),%edx
call   1040 <open@plt>
mov    -0x18(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    11a0 <tftp_create+0x80>
mov    -0x10(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <tftp_create+0x89>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tftp_create>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e8d(%rip),%rax
mov    0x2eae(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e85(%rip),%rax
or     (%rax),%edx
mov    0x2e74(%rip),%rax
or     (%rax),%edx
mov    0x2ea3(%rip),%rax
mov    0x2e74(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,%ebp
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
jne    117e <tftp_create+0x5e>
lea    0xe8a(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str = [32 x i8] c"The file [%s] already exists !\0A\00"
define i32 @tftp_create(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IROTH
%13 = or i32 %11, %12
store i32 %13, i32* %6
%14 = load i8*, i8** %4
%15 = load i32, i32* @O_CREAT
%16 = load i32, i32* @O_EXCL
%17 = or i32 %15, %16
%18 = load i32, i32* %6
%19 = call i32 @open(i8* %14, i32 %17, i32 %18)
%20 = load i32*, i32** %5
store i32 %19, i32* %20
%21 = icmp eq i32 %19, -1
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i8*, i8** %4
%24 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 -1, i32* %3
br label %28
25: ; preds = %2
%26 = load i32*, i32** %5
%27 = load i32, i32* %26
store i32 %27, i32* %3
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str = [32 x i8] c"The file [%s] already exists !\0A\00"
define i32 @tftp_create(i8* %0, i32* nocapture writeonly %1) {
%3 = load i32, i32* @S_IRUSR
%4 = load i32, i32* @S_IWUSR
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IRGRP
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IROTH
%9 = or i32 %7, %8
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_EXCL
%12 = or i32 %11, %10
%13 = tail call i32 @open(i8* %0, i32 %12, i32 %9)
store i32 %13, i32* %1
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %2, %15
ret i32 %13
}