#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_time;
  int /*<<< orphan*/ ut_name;
  int /*<<< orphan*/ ut_line;
};

/* Variables and functions */
int /*<<< orphan*/ _PATH_UTMP;
int /*<<< orphan*/ __bzero(int /*<<< orphan*/, int);
int /*<<< orphan*/ endutent();
scalar_t__ getutline_r(struct utmp *, struct utmp *, struct utmp **);
int /*<<< orphan*/ *pututline(struct utmp *);
int /*<<< orphan*/ setutent();
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int utmpname(int /*<<< orphan*/);
int logout(const char *line) {
  struct utmp tmp, utbuf;
  struct utmp *ut;
  int result = 0;
  if (utmpname(_PATH_UTMP) == -1)
    return 0;
  setutent();
  strncpy(tmp.ut_line, line, sizeof tmp.ut_line);
  if (getutline_r(&tmp, &utbuf, &ut) >= 0) {
    __bzero(ut->ut_name, sizeof ut->ut_name);
    time(&ut->ut_time);
    if (pututline(ut) != NULL)
      result = 1;
  }
  endutent();
  return result;
}


x86 assembly (clang, -O0):
<logout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1040 <utmpname@plt>
cmp    $0xffffffff,%eax
jne    11b6 <logout+0x36>
movl   $0x0,-0x4(%rbp)
jmp    122f <logout+0xaf>
mov    $0x0,%al
call   1090 <setutent@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1060 <getutline_r@plt>
cmp    $0x0,%rax
jl     1222 <logout+0xa2>
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%edi
mov    $0x4,%esi
call   1070 <__bzero@plt>
mov    -0x38(%rbp),%rdi
call   1080 <time@plt>
mov    -0x38(%rbp),%rdi
call   10a0 <pututline@plt>
cmp    $0x0,%rax
je     121d <logout+0x9d>
movl   $0x1,-0x3c(%rbp)
jmp    1222 <logout+0xa2>
mov    $0x0,%al
call   1050 <endutent@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logout>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1040 <utmpname@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     11fc <logout+0x7c>
xor    %eax,%eax
call   1090 <setutent@plt>
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1060 <getutline_r@plt>
test   %rax,%rax
js     11f5 <logout+0x75>
mov    (%rsp),%rax
mov    0x4(%rax),%edi
mov    $0x4,%esi
call   1070 <__bzero@plt>
mov    (%rsp),%rdi
call   1080 <time@plt>
mov    (%rsp),%rdi
call   10a0 <pututline@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
xor    %eax,%eax
call   1050 <endutent@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.utmp = type { i32, i32, i32 }
@_PATH_UTMP = global i32 0
define i32 @logout(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.utmp
%5 = alloca %struct.utmp
%6 = alloca %struct.utmp*
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
%8 = load i32, i32* @_PATH_UTMP
%9 = call i32 @utmpname(i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %36
12: ; preds = %1
%13 = call i32 (...) @setutent()
%14 = getelementptr inbounds %struct.utmp, %struct.utmp* %4, i32 0, i32 2
%15 = load i32, i32* %14
%16 = load i8*, i8** %3
%17 = call i32 @strncpy(i32 %15, i8* %16, i32 4)
%18 = call i64 @getutline_r(%struct.utmp* %4, %struct.utmp* %5, %struct.utmp** %6)
%19 = icmp sge i64 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %12
%21 = load %struct.utmp*, %struct.utmp** %6
%22 = getelementptr inbounds %struct.utmp, %struct.utmp* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = call i32 @__bzero(i32 %23, i32 4)
%25 = load %struct.utmp*, %struct.utmp** %6
%26 = getelementptr inbounds %struct.utmp, %struct.utmp* %25, i32 0, i32 0
%27 = call i32 @time(i32* %26)
%28 = load %struct.utmp*, %struct.utmp** %6
%29 = call i32* @pututline(%struct.utmp* %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %32
31: ; preds = %20
store i32 1, i32* %7
br label %32
32: ; preds = %31, %20
br label %33
33: ; preds = %32, %12
%34 = call i32 (...) @endutent()
%35 = load i32, i32* %7
store i32 %35, i32* %2
br label %36
36: ; preds = %33, %11
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
%struct.utmp = type { i32, i32, i32 }
@_PATH_UTMP = global i32 0
define i32 @logout(i8* %0) {
%2 = alloca %struct.utmp
%3 = alloca %struct.utmp
%4 = alloca %struct.utmp*
%5 = bitcast %struct.utmp* %2 to i8*
%6 = bitcast %struct.utmp* %3 to i8*
%7 = bitcast %struct.utmp** %4 to i8*
%8 = load i32, i32* @_PATH_UTMP
%9 = tail call i32 @utmpname(i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %31, label %11
11: ; preds = %1
%12 = tail call i32 (...) @setutent()
%13 = tail call i32 @strncpy(i32 undef, i8* %0, i32 4)
%14 = call i64 @getutline_r(%struct.utmp* %2, %struct.utmp* %3, %struct.utmp** %4)
%15 = icmp sgt i64 %14, -1
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load %struct.utmp*, %struct.utmp** %4
%18 = getelementptr inbounds %struct.utmp, %struct.utmp* %17, i64 0, i32 1
%19 = load i32, i32* %18
%20 = call i32 @__bzero(i32 %19, i32 4)
%21 = load %struct.utmp*, %struct.utmp** %4
%22 = getelementptr inbounds %struct.utmp, %struct.utmp* %21, i64 0, i32 0
%23 = call i32 @time(i32* %22)
%24 = load %struct.utmp*, %struct.utmp** %4
%25 = call i32* @pututline(%struct.utmp* %24)
%26 = icmp ne i32* %25, null
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %16, %11
%29 = phi i32 [ 0, %11 ], [ %27, %16 ]
%30 = call i32 (...) @endutent()
br label %31
31: ; preds = %1, %28
%32 = phi i32 [ %29, %28 ], [ 0, %1 ]
ret i32 %32
}