#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 utmpx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ FD_CLOEXEC;
int /*<<< orphan*/ F_SETFD;
int O_APPEND;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char const *, int);
int /*<<< orphan*/ write(int, struct utmpx const *, int);
void updwtmpx(const char *wtmpx_file, const struct utmpx *ut) {
  int fd = open(wtmpx_file, O_WRONLY | O_APPEND);
  if (fd < 0)
    return;
  fcntl(fd, F_SETFD, FD_CLOEXEC);
  write(fd, ut, sizeof(struct utmpx));
  close(fd);
}


x86 assembly (clang, -O0):
<updwtmpx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    0x2e5c(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117d <updwtmpx+0x3d>
jmp    11b0 <updwtmpx+0x70>
mov    -0x14(%rbp),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updwtmpx>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e7b(%rip),%rax
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     1198 <updwtmpx+0x58>
mov    %eax,%ebp
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1030 <fcntl@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.utmpx = type { i32 }
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
define void @updwtmpx(i8* %0, %struct.utmpx* %1) {
%3 = alloca i8*
%4 = alloca %struct.utmpx*
%5 = alloca i32
store i8* %0, i8** %3
store %struct.utmpx* %1, %struct.utmpx** %4
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_APPEND
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %24
14: ; preds = %2
%15 = load i32, i32* %5
%16 = load i32, i32* @F_SETFD
%17 = load i32, i32* @FD_CLOEXEC
%18 = call i32 @fcntl(i32 %15, i32 %16, i32 %17)
%19 = load i32, i32* %5
%20 = load %struct.utmpx*, %struct.utmpx** %4
%21 = call i32 @write(i32 %19, %struct.utmpx* %20, i32 4)
%22 = load i32, i32* %5
%23 = call i32 @close(i32 %22)
br label %24
24: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
%struct.utmpx = type { i32 }
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
define void @updwtmpx(i8* nocapture %0, %struct.utmpx* nocapture %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_APPEND
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @F_SETFD
%10 = load i32, i32* @FD_CLOEXEC
%11 = tail call i32 @fcntl(i32 %6, i32 %9, i32 %10)
%12 = tail call i32 @write(i32 %6, %struct.utmpx* %1, i32 4)
%13 = tail call i32 @close(i32 %6)
br label %14
14: ; preds = %2, %8
ret void
}