#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_WRONLY;
int /*<<< orphan*/ chmod(char *, unsigned long);
int /*<<< orphan*/ chown(char *, unsigned long, unsigned long);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error_msg_and_die(char *, char *);
int open(char *, int, unsigned long);
void add_new_file(char *name, char *path, unsigned long uid, unsigned long gid,
                  unsigned long mode) {
  int fd = open(path, O_CREAT | O_WRONLY, mode);
  if (fd < 0) {
    error_msg_and_die("%s: file can not be created!", path);
  } else {
    close(fd);
  }
  chmod(path, mode);
  chown(path, uid, gid);
}


x86 assembly (clang, -O0):
<add_new_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e50(%rip),%rax
or     (%rax),%esi
mov    -0x28(%rbp),%rdx
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11ad <add_new_file+0x5d>
mov    -0x10(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1040 <error_msg_and_die@plt>
jmp    11b5 <add_new_file+0x65>
mov    -0x2c(%rbp),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <chmod@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <chown@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_new_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    0x2e8d(%rip),%rax
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    %r8,%rdx
call   1070 <open@plt>
test   %eax,%eax
js     118e <add_new_file+0x3e>
mov    %eax,%edi
call   1030 <close@plt>
jmp    119d <add_new_file+0x4d>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <error_msg_and_die@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <chmod@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <chown@plt>

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str = [29 x i8] c"%s: file can not be created!\00"
define void @add_new_file(i8* %0, i8* %1, i64 %2, i64 %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%12 = load i8*, i8** %7
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_WRONLY
%15 = or i32 %13, %14
%16 = load i64, i64* %10
%17 = call i32 @open(i8* %12, i32 %15, i64 %16)
store i32 %17, i32* %11
%18 = load i32, i32* %11
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %5
%21 = load i8*, i8** %7
%22 = call i32 @error_msg_and_die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %26
23: ; preds = %5
%24 = load i32, i32* %11
%25 = call i32 @close(i32 %24)
br label %26
26: ; preds = %23, %20
%27 = load i8*, i8** %7
%28 = load i64, i64* %10
%29 = call i32 @chmod(i8* %27, i64 %28)
%30 = load i8*, i8** %7
%31 = load i64, i64* %8
%32 = load i64, i64* %9
%33 = call i32 @chown(i8* %30, i64 %31, i64 %32)
ret void
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str = [29 x i8] c"%s: file can not be created!\00"
define void @add_new_file(i8* nocapture readnone %0, i8* %1, i64 %2, i64 %3, i64 %4) {
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_WRONLY
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* %1, i32 %8, i64 %4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @error_msg_and_die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %15
13: ; preds = %5
%14 = tail call i32 @close(i32 %9)
br label %15
15: ; preds = %13, %11
%16 = tail call i32 @chmod(i8* %1, i64 %4)
%17 = tail call i32 @chown(i8* %1, i64 %2, i64 %3)
ret void
}