#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 {
  scalar_t__ ut_type;
  int ut_pid;
  char *ut_line;
  char *ut_user;
  char *ut_host;
};

/* Variables and functions */
scalar_t__ DEAD_PROCESS;
struct utmp *getutent();
int /*<<< orphan*/ printf(char *, char *, int, char *, char *, char *);
int /*<<< orphan*/ setutent();
char *utTypeName(scalar_t__);
int main() {
  struct utmp *ut;
  setutent();
  while ((ut = getutent())) {
    if (ut->ut_type == DEAD_PROCESS)
      continue;
    printf("%-13s %5d /dev/%-5s %-8s %-15s\n", utTypeName(ut->ut_type),
           ut->ut_pid, ut->ut_line, *ut->ut_user ? ut->ut_user : "(user)",
           ut->ut_host);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <setutent@plt>
mov    $0x0,%al
call   1040 <getutent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     120a <main+0xca>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    1187 <main+0x47>
jmp    1156 <main+0x16>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <utTypeName@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d2 <main+0x92>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11e2 <main+0xa2>
lea    0xe47(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11e2 <main+0xa2>
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%r8
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%r9
lea    0xe00(%rip),%rdi
call   1030 <printf@plt>
jmp    1156 <main+0x16>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <setutent@plt>
xor    %eax,%eax
call   1040 <getutent@plt>
test   %rax,%rax
je     11c0 <main+0x80>
mov    %rax,%rbx
mov    0x2e7b(%rip),%r15
lea    0xeb4(%rip),%r12
lea    0xe8d(%rip),%r14
jmp    118f <main+0x4f>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <getutent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c0 <main+0x80>
mov    (%rbx),%rdi
cmp    (%r15),%rdi
je     1180 <main+0x40>
call   1060 <utTypeName@plt>
mov    0x8(%rbx),%edx
mov    0x18(%rbx),%r8
cmpb   $0x0,(%r8)
mov    0x10(%rbx),%rcx
cmove  %r12,%r8
mov    0x20(%rbx),%r9
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
jmp    1180 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.utmp = type { i64, i32, i8*, i8*, i8* }
@DEAD_PROCESS = global i64 0
@.str = [32 x i8] c"%-13s %5d /dev/%-5s %-8s %-15s\0A\00"
@.str.1 = [7 x i8] c"(user)\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.utmp*
store i32 0, i32* %1
%3 = call i32 (...) @setutent()
br label %4
4: ; preds = %36, %13, %0
%5 = call %struct.utmp* (...) @getutent()
store %struct.utmp* %5, %struct.utmp** %2
%6 = icmp ne %struct.utmp* %5, null
br i1 %6, label %7, label %42
7: ; preds = %4
%8 = load %struct.utmp*, %struct.utmp** %2
%9 = getelementptr inbounds %struct.utmp, %struct.utmp* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @DEAD_PROCESS
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %7
br label %4
14: ; preds = %7
%15 = load %struct.utmp*, %struct.utmp** %2
%16 = getelementptr inbounds %struct.utmp, %struct.utmp* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = call i8* @utTypeName(i64 %17)
%19 = load %struct.utmp*, %struct.utmp** %2
%20 = getelementptr inbounds %struct.utmp, %struct.utmp* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load %struct.utmp*, %struct.utmp** %2
%23 = getelementptr inbounds %struct.utmp, %struct.utmp* %22, i32 0, i32 2
%24 = load i8*, i8** %23
%25 = load %struct.utmp*, %struct.utmp** %2
%26 = getelementptr inbounds %struct.utmp, %struct.utmp* %25, i32 0, i32 3
%27 = load i8*, i8** %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %14
%32 = load %struct.utmp*, %struct.utmp** %2
%33 = getelementptr inbounds %struct.utmp, %struct.utmp* %32, i32 0, i32 3
%34 = load i8*, i8** %33
br label %36
35: ; preds = %14
br label %36
36: ; preds = %35, %31
%37 = phi i8* [ %34, %31 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %35 ]
%38 = load %struct.utmp*, %struct.utmp** %2
%39 = getelementptr inbounds %struct.utmp, %struct.utmp* %38, i32 0, i32 4
%40 = load i8*, i8** %39
%41 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %21, i8* %24, i8* %37, i8* %40)
br label %4
42: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
%struct.utmp = type { i64, i32, i8*, i8*, i8* }
@DEAD_PROCESS = global i64 0
@.str = [32 x i8] c"%-13s %5d /dev/%-5s %-8s %-15s\0A\00"
@.str.1 = [7 x i8] c"(user)\00"
define i32 @main() {
%1 = tail call i32 (...) @setutent()
%2 = tail call %struct.utmp* (...) @getutent()
%3 = icmp eq %struct.utmp* %2, null
br i1 %3, label %27, label %4
4: ; preds = %0, %24
%5 = phi %struct.utmp* [ %25, %24 ], [ %2, %0 ]
%6 = getelementptr inbounds %struct.utmp, %struct.utmp* %5, i64 0, i32 0
%7 = load i64, i64* %6
%8 = load i64, i64* @DEAD_PROCESS
%9 = icmp eq i64 %7, %8
br i1 %9, label %24, label %10
10: ; preds = %4
%11 = tail call i8* @utTypeName(i64 %7)
%12 = getelementptr inbounds %struct.utmp, %struct.utmp* %5, i64 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.utmp, %struct.utmp* %5, i64 0, i32 2
%15 = load i8*, i8** %14
%16 = getelementptr inbounds %struct.utmp, %struct.utmp* %5, i64 0, i32 3
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %17
%21 = getelementptr inbounds %struct.utmp, %struct.utmp* %5, i64 0, i32 4
%22 = load i8*, i8** %21
%23 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %13, i8* %15, i8* %20, i8* %22)
br label %24
24: ; preds = %10, %4
%25 = tail call %struct.utmp* (...) @getutent()
%26 = icmp eq %struct.utmp* %25, null
br i1 %26, label %27, label %4
27: ; preds = %24, %0
ret i32 0
}