#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 tv_sec;
};
struct utmp {
  scalar_t__ ut_type;
  TYPE_1__ ut_tv;
  int /*<<< orphan*/ ut_host;
  int /*<<< orphan*/ ut_line;
  int /*<<< orphan*/ ut_user;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ USER_PROCESS;
scalar_t__ errno;
struct utmp *getutent();
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int get_user(char *username, char *tty, char *hostname, int *tstamp,
             short *user_proc) {
  struct utmp *ut = getutent();
  if (ut == NULL) {
    if (errno == 0 || errno == ENOENT)
      return -1;
    else
      return errno;
  } else {
    strncpy(username, ut->ut_user, sizeof(ut->ut_user) - 1);
    strncpy(tty, ut->ut_line, sizeof(ut->ut_line) - 1);
    strncpy(hostname, ut->ut_host, sizeof(ut->ut_host) - 1);
    *tstamp = ut->ut_tv.tv_sec;
    if (ut->ut_type == USER_PROCESS)
      *user_proc = (short)1;
    else
      *user_proc = (short)0;
    return 0;
  }
}


x86 assembly (clang, -O0):
<get_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    $0x0,%al
call   1040 <getutent@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    119b <get_user+0x7b>
mov    0x2e7f(%rip),%rax
cmpq   $0x0,(%rax)
je     117d <get_user+0x5d>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%rax
jne    1189 <get_user+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    121c <get_user+0xfc>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    121c <get_user+0xfc>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0x14(%rax),%esi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%esi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%esi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%rax
jne    120c <get_user+0xec>
mov    -0x30(%rbp),%rax
movw   $0x1,(%rax)
jmp    1215 <get_user+0xf5>
mov    -0x30(%rbp),%rax
movw   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_user>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,(%rsp)
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getutent@plt>
test   %rax,%rax
je     119d <get_user+0x7d>
mov    %rax,%rbx
mov    0x14(%rax),%esi
mov    %r14,%rdi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    0x10(%rbx),%esi
mov    %r13,%rdi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    0xc(%rbx),%esi
mov    %r12,%rdi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    0x8(%rbx),%eax
mov    %eax,(%r15)
mov    (%rbx),%rax
mov    0x2e5c(%rip),%rcx
xor    %edx,%edx
cmp    (%rcx),%rax
sete   %dl
mov    (%rsp),%rax
mov    %dx,(%rax)
jmp    11c1 <get_user+0xa1>
mov    0x2e34(%rip),%rax
mov    (%rax),%rax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%rax
mov    $0xffffffff,%ecx
cmovne %eax,%ecx
cmp    $0x1,%rax
sbb    %ebp,%ebp
or     %ecx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.utmp = type { i64, %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@USER_PROCESS = global i64 0
define i32 @get_user(i8* %0, i8* %1, i8* %2, i32* %3, i16* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i16*
%12 = alloca %struct.utmp*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i16* %4, i16** %11
%13 = call %struct.utmp* (...) @getutent()
store %struct.utmp* %13, %struct.utmp** %12
%14 = load %struct.utmp*, %struct.utmp** %12
%15 = icmp eq %struct.utmp* %14, null
br i1 %15, label %16, label %27
16: ; preds = %5
%17 = load i64, i64* @errno
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = load i64, i64* @errno
%21 = load i64, i64* @ENOENT
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19, %16
store i32 -1, i32* %6
br label %58
24: ; preds = %19
%25 = load i64, i64* @errno
%26 = trunc i64 %25 to i32
store i32 %26, i32* %6
br label %58
27: ; preds = %5
%28 = load i8*, i8** %7
%29 = load %struct.utmp*, %struct.utmp** %12
%30 = getelementptr inbounds %struct.utmp, %struct.utmp* %29, i32 0, i32 4
%31 = load i32, i32* %30
%32 = call i32 @strncpy(i8* %28, i32 %31, i32 3)
%33 = load i8*, i8** %8
%34 = load %struct.utmp*, %struct.utmp** %12
%35 = getelementptr inbounds %struct.utmp, %struct.utmp* %34, i32 0, i32 3
%36 = load i32, i32* %35
%37 = call i32 @strncpy(i8* %33, i32 %36, i32 3)
%38 = load i8*, i8** %9
%39 = load %struct.utmp*, %struct.utmp** %12
%40 = getelementptr inbounds %struct.utmp, %struct.utmp* %39, i32 0, i32 2
%41 = load i32, i32* %40
%42 = call i32 @strncpy(i8* %38, i32 %41, i32 3)
%43 = load %struct.utmp*, %struct.utmp** %12
%44 = getelementptr inbounds %struct.utmp, %struct.utmp* %43, i32 0, i32 1
%45 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = load i32*, i32** %10
store i32 %46, i32* %47
%48 = load %struct.utmp*, %struct.utmp** %12
%49 = getelementptr inbounds %struct.utmp, %struct.utmp* %48, i32 0, i32 0
%50 = load i64, i64* %49
%51 = load i64, i64* @USER_PROCESS
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %27
%54 = load i16*, i16** %11
store i16 1, i16* %54
br label %57
55: ; preds = %27
%56 = load i16*, i16** %11
store i16 0, i16* %56
br label %57
57: ; preds = %55, %53
store i32 0, i32* %6
br label %58
58: ; preds = %57, %24, %23
%59 = load i32, i32* %6
ret i32 %59
}

LLVM IR (-O2):
%struct.utmp = type { i64, %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@USER_PROCESS = global i64 0
define i32 @get_user(i8* %0, i8* %1, i8* %2, i32* nocapture writeonly %3, i16* nocapture writeonly %4) {
%6 = tail call %struct.utmp* (...) @getutent()
%7 = icmp eq %struct.utmp* %6, null
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
%11 = load i64, i64* @ENOENT
%12 = icmp eq i64 %9, %11
%13 = select i1 %10, i1 true, i1 %12
%14 = trunc i64 %9 to i32
%15 = select i1 %13, i32 -1, i32 %14
br label %33
16: ; preds = %5
%17 = getelementptr inbounds %struct.utmp, %struct.utmp* %6, i64 0, i32 4
%18 = load i32, i32* %17
%19 = tail call i32 @strncpy(i8* %0, i32 %18, i32 3)
%20 = getelementptr inbounds %struct.utmp, %struct.utmp* %6, i64 0, i32 3
%21 = load i32, i32* %20
%22 = tail call i32 @strncpy(i8* %1, i32 %21, i32 3)
%23 = getelementptr inbounds %struct.utmp, %struct.utmp* %6, i64 0, i32 2
%24 = load i32, i32* %23
%25 = tail call i32 @strncpy(i8* %2, i32 %24, i32 3)
%26 = getelementptr inbounds %struct.utmp, %struct.utmp* %6, i64 0, i32 1, i32 0
%27 = load i32, i32* %26
store i32 %27, i32* %3
%28 = getelementptr inbounds %struct.utmp, %struct.utmp* %6, i64 0, i32 0
%29 = load i64, i64* %28
%30 = load i64, i64* @USER_PROCESS
%31 = icmp eq i64 %29, %30
%32 = zext i1 %31 to i16
store i16 %32, i16* %4
br label %33
33: ; preds = %8, %16
%34 = phi i32 [ 0, %16 ], [ %15, %8 ]
ret i32 %34
}