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

/* Variables and functions */
int /*<<< orphan*/ F_LOCK;
int /*<<< orphan*/ F_ULOCK;
int O_APPEND;
int O_WRONLY;
int /*<<< orphan*/ close(int);
scalar_t__ lockf(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char const *, int);
int /*<<< orphan*/ write(int, struct utmp const *, int);
void updwtmp(const char *wtmp_file, const struct utmp *lutmp) {
  int fd;
  fd = open(wtmp_file, O_APPEND | O_WRONLY);
  if (fd >= 0) {
    if (lockf(fd, F_LOCK, 0) == 0) {
      write(fd, lutmp, sizeof(*lutmp));
      lockf(fd, F_ULOCK, 0);
      close(fd);
    }
  }
}


x86 assembly (clang, -O0):
<updwtmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    0x2e64(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11c6 <updwtmp+0x86>
mov    -0x14(%rbp),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <lockf@plt>
cmp    $0x0,%rax
jne    11c1 <updwtmp+0x81>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <lockf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    11c6 <updwtmp+0x86>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updwtmp>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e72(%rip),%rax
mov    0x2e73(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     117b <updwtmp+0x3b>
mov    %eax,%ebx
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <lockf@plt>
test   %rax,%rax
je     1183 <updwtmp+0x43>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <lockf@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <close@plt>

LLVM IR (-O0):
%struct.utmp = type { i32 }
@O_APPEND = global i32 0
@O_WRONLY = global i32 0
@F_LOCK = global i32 0
@F_ULOCK = global i32 0
define void @updwtmp(i8* %0, %struct.utmp* %1) {
%3 = alloca i8*
%4 = alloca %struct.utmp*
%5 = alloca i32
store i8* %0, i8** %3
store %struct.utmp* %1, %struct.utmp** %4
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_APPEND
%8 = load i32, i32* @O_WRONLY
%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 sge i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %2
%14 = load i32, i32* %5
%15 = load i32, i32* @F_LOCK
%16 = call i64 @lockf(i32 %14, i32 %15, i32 0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i32, i32* %5
%20 = load %struct.utmp*, %struct.utmp** %4
%21 = call i32 @write(i32 %19, %struct.utmp* %20, i32 4)
%22 = load i32, i32* %5
%23 = load i32, i32* @F_ULOCK
%24 = call i64 @lockf(i32 %22, i32 %23, i32 0)
%25 = load i32, i32* %5
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %18, %13
br label %28
28: ; preds = %27, %2
ret void
}

LLVM IR (-O2):
%struct.utmp = type { i32 }
@O_APPEND = global i32 0
@O_WRONLY = global i32 0
@F_LOCK = global i32 0
@F_ULOCK = global i32 0
define void @updwtmp(i8* nocapture %0, %struct.utmp* nocapture %1) {
%3 = load i32, i32* @O_APPEND
%4 = load i32, i32* @O_WRONLY
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = load i32, i32* @F_LOCK
%10 = tail call i64 @lockf(i32 %6, i32 %9, i32 0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = tail call i32 @write(i32 %6, %struct.utmp* %1, i32 4)
%14 = load i32, i32* @F_ULOCK
%15 = tail call i64 @lockf(i32 %6, i32 %14, i32 0)
%16 = tail call i32 @close(i32 %6)
br label %17
17: ; preds = %8, %12, %2
ret void
}