#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 */
struct stat {
  int /*<<< orphan*/ st_nlink;
  int /*<<< orphan*/ st_ino;
  int /*<<< orphan*/ st_dev;
};

/* Variables and functions */
int creat(char *, unsigned short);
int /*<<< orphan*/ filelink(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, char *);
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ unlink(char *);
int create(char *pathname, unsigned short mode) {
  int fd;
  unlink(pathname);
  if ((fd = creat(pathname, mode)) >= 0) {
    struct stat statbuf;
    fstat(fd, &statbuf);
    filelink(statbuf.st_dev, statbuf.st_ino, statbuf.st_nlink, pathname);
  }
  return (fd);
}


x86 assembly (clang, -O0):
<create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%esi
call   1050 <creat@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jl     1193 <create+0x53>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <fstat@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x8(%rbp),%rcx
call   1040 <filelink@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <creat@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1180 <create+0x40>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
call   1060 <fstat@plt>
mov    0x10(%rsp),%edi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%esi
mov    %rbx,%rcx
call   1040 <filelink@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
define i32 @create(i8* %0, i16 zeroext %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i32
%6 = alloca %struct.stat
store i8* %0, i8** %3
store i16 %1, i16* %4
%7 = load i8*, i8** %3
%8 = call i32 @unlink(i8* %7)
%9 = load i8*, i8** %3
%10 = load i16, i16* %4
%11 = call i32 @creat(i8* %9, i16 zeroext %10)
store i32 %11, i32* %5
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = load i32, i32* %5
%15 = call i32 @fstat(i32 %14, %struct.stat* %6)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i8*, i8** %3
%23 = call i32 @filelink(i32 %17, i32 %19, i32 %21, i8* %22)
br label %24
24: ; preds = %13, %2
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
define i32 @create(i8* %0, i16 zeroext %1) {
%3 = alloca %struct.stat
%4 = tail call i32 @unlink(i8* %0)
%5 = tail call i32 @creat(i8* %0, i16 zeroext %1)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = bitcast %struct.stat* %3 to i8*
%9 = call i32 @fstat(i32 %5, %struct.stat* %3)
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 @filelink(i32 %11, i32 %13, i32 %15, i8* %0)
br label %17
17: ; preds = %7, %2
ret i32 %5
}