#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ *fdopen(int, char *);
int open(char *, int, int);
FILE *os_createnewfile(char *fname) {
  int fd;
  FILE *ret;
  fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0644);
  if (fd == -1)
    return NULL;
  ret = fdopen(fd, "w");
  return ret;
}


x86 assembly (clang, -O0):
<os_createnewfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
mov    0x2eb8(%rip),%rax
or     (%rax),%esi
mov    0x2ea7(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    116f <os_createnewfile+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    118a <os_createnewfile+0x6a>
mov    -0x14(%rbp),%edi
lea    0xe87(%rip),%rsi
call   1030 <fdopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_createnewfile>:
push   %rax
mov    0x2eb0(%rip),%rax
mov    0x2ec9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2eb6(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     115a <os_createnewfile+0x3a>
lea    0xeae(%rip),%rsi
mov    %eax,%edi
pop    %rax
jmp    1030 <fdopen@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [2 x i8] c"w\00"
define i32* @os_createnewfile(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %6, i32 %11, i32 420)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %1
store i32* null, i32** %2
br label %20
16: ; preds = %1
%17 = load i32, i32* %4
%18 = call i32* @fdopen(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %5
%19 = load i32*, i32** %5
store i32* %19, i32** %2
br label %20
20: ; preds = %16, %15
%21 = load i32*, i32** %2
ret i32* %21
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [2 x i8] c"w\00"
define noalias i32* @os_createnewfile(i8* nocapture %0) {
%2 = load i32, i32* @O_RDWR
%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 420)
%8 = icmp eq i32 %7, -1
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = tail call i32* @fdopen(i32 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %1, %9
%12 = phi i32* [ %10, %9 ], [ null, %1 ]
ret i32* %12
}