#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 /*<<< orphan*/ ut_tv;
  int /*<<< orphan*/ ut_host;
  int /*<<< orphan*/ ut_name;
  int /*<<< orphan*/ ut_line;
  int /*<<< orphan*/ ut_pid;
  int /*<<< orphan*/ ut_type;
};
typedef int /*<<< orphan*/ lutmp;

/* Variables and functions */
int /*<<< orphan*/ DEAD_PROCESS;
int /*<<< orphan*/ USER_PROCESS;
int /*<<< orphan*/ _PATH_WTMP;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ gettimeofday(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct utmp *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int /*<<< orphan*/ updwtmp(int /*<<< orphan*/, struct utmp *);
void logwtmp(const char *line, const char *name, const char *host) {
  struct utmp lutmp;
  memset(&lutmp, 0, sizeof(lutmp));
  lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS;
  lutmp.ut_pid = getpid();
  strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line) - 1);
  strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name) - 1);
  strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host) - 1);
  gettimeofday(&lutmp.ut_tv, NULL);
  updwtmp(_PATH_WTMP, &lutmp);
}


x86 assembly (clang, -O0):
<logwtmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11a0 <logwtmp+0x50>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a0 <logwtmp+0x50>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    11ac <logwtmp+0x5c>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1050 <updwtmp@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logwtmp>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
test   %rbx,%rbx
je     1186 <logwtmp+0x36>
cmpb   $0x0,(%rbx)
je     1186 <logwtmp+0x36>
mov    0x2e64(%rip),%rax
jmp    118d <logwtmp+0x3d>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,0x18(%rsp)
mov    0x14(%rsp),%edi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    0xc(%rsp),%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1050 <updwtmp@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.utmp = type { i32, i32, i32, i32, i32, i32 }
@USER_PROCESS = global i32 0
@DEAD_PROCESS = global i32 0
@_PATH_WTMP = global i32 0
define void @logwtmp(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.utmp
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = call i32 @memset(%struct.utmp* %7, i32 0, i32 24)
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %18
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i32, i32* @USER_PROCESS
br label %20
18: ; preds = %11, %3
%19 = load i32, i32* @DEAD_PROCESS
br label %20
20: ; preds = %18, %16
%21 = phi i32 [ %17, %16 ], [ %19, %18 ]
%22 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 5
store i32 %21, i32* %22
%23 = call i32 (...) @getpid()
%24 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 4
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 3
%26 = load i32, i32* %25
%27 = load i8*, i8** %4
%28 = call i32 @strncpy(i32 %26, i8* %27, i32 3)
%29 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 2
%30 = load i32, i32* %29
%31 = load i8*, i8** %5
%32 = call i32 @strncpy(i32 %30, i8* %31, i32 3)
%33 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 1
%34 = load i32, i32* %33
%35 = load i8*, i8** %6
%36 = call i32 @strncpy(i32 %34, i8* %35, i32 3)
%37 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 0
%38 = call i32 @gettimeofday(i32* %37, i32* null)
%39 = load i32, i32* @_PATH_WTMP
%40 = call i32 @updwtmp(i32 %39, %struct.utmp* %7)
ret void
}

LLVM IR (-O2):
%struct.utmp = type { i32, i32, i32, i32, i32, i32 }
@USER_PROCESS = global i32 0
@DEAD_PROCESS = global i32 0
@_PATH_WTMP = global i32 0
define void @logwtmp(i8* %0, i8* %1, i8* %2) {
%4 = alloca %struct.utmp
%5 = bitcast %struct.utmp* %4 to i8*
%6 = call i32 @memset(%struct.utmp* %4, i32 0, i32 24)
%7 = icmp eq i8* %1, null
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8, %3
br label %12
12: ; preds = %8, %11
%13 = phi i32* [ @DEAD_PROCESS, %11 ], [ @USER_PROCESS, %8 ]
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.utmp, %struct.utmp* %4, i64 0, i32 5
store i32 %14, i32* %15
%16 = call i32 (...) @getpid()
%17 = getelementptr inbounds %struct.utmp, %struct.utmp* %4, i64 0, i32 4
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.utmp, %struct.utmp* %4, i64 0, i32 3
%19 = load i32, i32* %18
%20 = call i32 @strncpy(i32 %19, i8* %0, i32 3)
%21 = getelementptr inbounds %struct.utmp, %struct.utmp* %4, i64 0, i32 2
%22 = load i32, i32* %21
%23 = call i32 @strncpy(i32 %22, i8* %1, i32 3)
%24 = getelementptr inbounds %struct.utmp, %struct.utmp* %4, i64 0, i32 1
%25 = load i32, i32* %24
%26 = call i32 @strncpy(i32 %25, i8* %2, i32 3)
%27 = getelementptr inbounds %struct.utmp, %struct.utmp* %4, i64 0, i32 0
%28 = call i32 @gettimeofday(i32* %27, i32* null)
%29 = load i32, i32* @_PATH_WTMP
%30 = call i32 @updwtmp(i32 %29, %struct.utmp* %4)
ret void
}