#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct utmp {
  TYPE_1__ ut_tv;
  int /*<<< orphan*/ ut_host;
  int /*<<< orphan*/ ut_name;
  int /*<<< orphan*/ ut_line;
  int /*<<< orphan*/ ut_type;
  int /*<<< orphan*/ ut_pid;
};
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ DEAD_PROCESS;
int /*<<< orphan*/ USER_PROCESS;
int /*<<< orphan*/ _PATH_WTMP;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memccpy(int /*<<< orphan*/, char const *, int /*<<< orphan*/,
                           int);
int /*<<< orphan*/ memset(struct utmp *, int /*<<< orphan*/, int);
int /*<<< orphan*/ updwtmp(int /*<<< orphan*/, struct utmp *);
void logwtmp(const char *line, const char *name, const char *host) {
  struct utmp ut;
  memset(&ut, 0, sizeof(struct utmp));
  ut.ut_pid = getpid();
  ut.ut_type = name[0] ? USER_PROCESS : DEAD_PROCESS;
  memccpy(ut.ut_line, line, 0, sizeof ut.ut_line);
  memccpy(ut.ut_name, name, 0, sizeof ut.ut_name);
  memccpy(ut.ut_host, host, 0, sizeof ut.ut_host);
  if (sizeof(ut.ut_tv) == sizeof(struct timeval))
    gettimeofday((struct timeval *)&ut.ut_tv, NULL);
  else {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    ut.ut_tv.tv_sec = tv.tv_sec;
    ut.ut_tv.tv_usec = tv.tv_usec;
  }
  updwtmp(_PATH_WTMP, &ut);
}


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    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x1c,%edx
call   1060 <memset@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119f <logwtmp+0x4f>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    11ab <logwtmp+0x5b>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1070 <memccpy@plt>
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1070 <memccpy@plt>
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1070 <memccpy@plt>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1040 <updwtmp@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logwtmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1c,%edx
call   1060 <memset@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,0x20(%rsp)
cmpb   $0x0,(%rbx)
jne    1191 <logwtmp+0x41>
mov    0x2e41(%rip),%rax
jmp    1198 <logwtmp+0x48>
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x18(%rsp),%edi
mov    %r12,%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1070 <memccpy@plt>
mov    0x14(%rsp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1070 <memccpy@plt>
mov    0x10(%rsp),%edi
mov    %r15,%rsi
xor    %edx,%edx
mov    $0x4,%ecx
call   1070 <memccpy@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1040 <updwtmp@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.utmp = type { %struct.TYPE_2__, i32, i32, i32, i32, i32 }
%struct.TYPE_2__ = type { i32, i32 }
%struct.timeval = type { 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 28)
%9 = call i32 (...) @getpid()
%10 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 5
store i32 %9, i32* %10
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
%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 = %3
%17 = load i32, i32* @USER_PROCESS
br label %20
18: ; preds = %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 4
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 3
%24 = load i32, i32* %23
%25 = load i8*, i8** %4
%26 = call i32 @memccpy(i32 %24, i8* %25, i32 0, i32 4)
%27 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 2
%28 = load i32, i32* %27
%29 = load i8*, i8** %5
%30 = call i32 @memccpy(i32 %28, i8* %29, i32 0, i32 4)
%31 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 1
%32 = load i32, i32* %31
%33 = load i8*, i8** %6
%34 = call i32 @memccpy(i32 %32, i8* %33, i32 0, i32 4)
%35 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 0
%36 = bitcast %struct.TYPE_2__* %35 to %struct.timeval*
%37 = call i32 @gettimeofday(%struct.timeval* %36, i32* null)
%38 = load i32, i32* @_PATH_WTMP
%39 = call i32 @updwtmp(i32 %38, %struct.utmp* %7)
ret void
}

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