#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 register_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ AT_FDCWD;
int O_CREAT;
int O_EXCL;
int O_WRONLY;
int /*<<< orphan*/ SYS_openat;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ assert(int);
int inject_syscall(int /*<<< orphan*/, int, int /*<<< orphan*/,
                   int /*<<< orphan*/, char *, unsigned long long,
                   int /*<<< orphan*/);
int openat_i(pid_t pid, char *pathname) {
  register_t ret = inject_syscall(
      pid, 4, SYS_openat, AT_FDCWD, pathname,
      (long long unsigned)(O_WRONLY | O_CREAT | O_EXCL), S_IRWXU);
  assert((int)ret > 0);
  return ret;
}


x86 assembly (clang, -O0):
<openat_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
mov    0x2e6e(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%r8
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    0x2ea0(%rip),%rsi
or     (%rsi),%eax
mov    0x2e67(%rip),%rsi
or     (%rsi),%eax
movslq %eax,%r9
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    $0x4,%esi
mov    %eax,(%rsp)
call   1040 <inject_syscall@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openat_i>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r8
mov    0x2ea9(%rip),%rax
mov    (%rax),%edx
mov    0x2e78(%rip),%rax
mov    (%rax),%ecx
mov    0x2e77(%rip),%rax
mov    0x2eb0(%rip),%rsi
mov    (%rsi),%esi
or     (%rax),%esi
movslq %esi,%rax
mov    0x2e72(%rip),%rsi
movslq (%rsi),%r9
or     %rax,%r9
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    $0x4,%esi
call   1040 <inject_syscall@plt>
mov    %eax,%ebx
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1030 <assert@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SYS_openat = global i32 0
@AT_FDCWD = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRWXU = global i32 0
define i32 @openat_i(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = load i32, i32* @SYS_openat
%8 = load i32, i32* @AT_FDCWD
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @O_EXCL
%14 = or i32 %12, %13
%15 = sext i32 %14 to i64
%16 = load i32, i32* @S_IRWXU
%17 = call i32 @inject_syscall(i32 %6, i32 4, i32 %7, i32 %8, i8* %9, i64 %15, i32 %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp sgt i32 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
@SYS_openat = global i32 0
@AT_FDCWD = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRWXU = global i32 0
define i32 @openat_i(i32 %0, i8* %1) {
%3 = load i32, i32* @SYS_openat
%4 = load i32, i32* @AT_FDCWD
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @O_EXCL
%9 = or i32 %7, %8
%10 = sext i32 %9 to i64
%11 = load i32, i32* @S_IRWXU
%12 = tail call i32 @inject_syscall(i32 %0, i32 4, i32 %3, i32 %4, i8* %1, i64 %10, i32 %11)
%13 = icmp sgt i32 %12, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
ret i32 %12
}