#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*/);
int /*<<< orphan*/ write(int, char const *, int);
extern void updwtmp(const char *wtmp_file, const struct utmp *lutmp) {
  int fd;
  fd = open(wtmp_file, O_APPEND | O_WRONLY, 0);
  if (fd >= 0) {
    if (lockf(fd, F_LOCK, 0) == 0) {
      write(fd, (const char *)lutmp, sizeof(struct utmp));
      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
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11c8 <updwtmp+0x88>
mov    -0x14(%rbp),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <lockf@plt>
cmp    $0x0,%rax
jne    11c3 <updwtmp+0x83>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <lockf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    11c8 <updwtmp+0x88>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updwtmp>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e73(%rip),%rax
mov    0x2e74(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
test   %eax,%eax
js     117c <updwtmp+0x3c>
mov    %eax,%ebp
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <lockf@plt>
test   %rax,%rax
je     1183 <updwtmp+0x43>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <lockf@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
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, i32 0)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %29
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 %28
18: ; preds = %13
%19 = load i32, i32* %5
%20 = load %struct.utmp*, %struct.utmp** %4
%21 = bitcast %struct.utmp* %20 to i8*
%22 = call i32 @write(i32 %19, i8* %21, i32 4)
%23 = load i32, i32* %5
%24 = load i32, i32* @F_ULOCK
%25 = call i64 @lockf(i32 %23, i32 %24, i32 0)
%26 = load i32, i32* %5
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %18, %13
br label %29
29: ; preds = %28, %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, i32 0)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %18
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 %18
12: ; preds = %8
%13 = bitcast %struct.utmp* %1 to i8*
%14 = tail call i32 @write(i32 %6, i8* %13, i32 4)
%15 = load i32, i32* @F_ULOCK
%16 = tail call i64 @lockf(i32 %6, i32 %15, i32 0)
%17 = tail call i32 @close(i32 %6)
br label %18
18: ; preds = %8, %12, %2
ret void
}