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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ USER_PROCESS;
char *ctime(int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *, char *);
int read(int, struct utmp *, int);
int main() {
  struct utmp usr;
  int fd = -1;
  fd = open("/var/run/utmp", O_RDONLY);
  if (-1 == fd)
    perror("open");
  while (1) {
    int ret = read(fd, &usr, sizeof(usr));
    if (ret == 0) {
      break;
    } else if (usr.ut_type == USER_PROCESS && (ret != 0)) {
      printf("%s\t%s\t\t%s\n", usr.ut_user, usr.ut_line,
             ctime(&usr.ut_tv.tv_sec));
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x2c(%rbp),%eax
jne    1198 <main+0x48>
lea    0xe7b(%rip),%rdi
call   1070 <perror@plt>
jmp    119d <main+0x4d>
mov    -0x2c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    11c0 <main+0x70>
jmp    121c <main+0xcc>
mov    -0x28(%rbp),%rax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
jne    1212 <main+0xc2>
cmpl   $0x0,-0x30(%rbp)
je     1212 <main+0xc2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x18,%rdi
call   1030 <ctime@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
jmp    1217 <main+0xc7>
jmp    119d <main+0x4d>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     1206 <main+0xb6>
lea    0x8(%rsp),%rsi
mov    %r13d,%edi
mov    $0x20,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11f5 <main+0xa5>
mov    0x2e4c(%rip),%r14
lea    0xe70(%rip),%r15
lea    0x8(%rsp),%r12
jmp    11c4 <main+0x74>
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x20,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11f5 <main+0xa5>
mov    0x8(%rsp),%rax
cmp    (%r14),%rax
jne    11b0 <main+0x60>
mov    0x10(%rsp),%rbx
mov    0x18(%rsp),%rbp
lea    0x20(%rsp),%rdi
call   1030 <ctime@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1040 <printf@plt>
jmp    11b0 <main+0x60>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe01(%rip),%rdi
call   1070 <perror@plt>
jmp    117f <main+0x2f>

LLVM IR (-O0):
%struct.utmp = type { i64, i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [14 x i8] c"/var/run/utmp\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@USER_PROCESS = global i64 0
@.str.2 = [11 x i8] c"%s\09%s\09\09%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.utmp
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %3
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 -1, %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
br label %12
12: ; preds = %11, %36
%13 = load i32, i32* %3
%14 = call i32 @read(i32 %13, %struct.utmp* %2, i32 32)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %37
18: ; preds = %12
%19 = getelementptr inbounds %struct.utmp, %struct.utmp* %2, i32 0, i32 0
%20 = load i64, i64* %19
%21 = load i64, i64* @USER_PROCESS
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %18
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = getelementptr inbounds %struct.utmp, %struct.utmp* %2, i32 0, i32 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.utmp, %struct.utmp* %2, i32 0, i32 2
%30 = load i8*, i8** %29
%31 = getelementptr inbounds %struct.utmp, %struct.utmp* %2, i32 0, i32 3
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
%33 = call i8* @ctime(i32* %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %28, i8* %30, i8* %33)
br label %35
35: ; preds = %26, %23, %18
br label %36
36: ; preds = %35
br label %12
37: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
%struct.utmp = type { i64, i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [14 x i8] c"/var/run/utmp\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@USER_PROCESS = global i64 0
@.str.2 = [11 x i8] c"%s\09%s\09\09%s\0A\00"
define i32 @main() {
%1 = alloca %struct.utmp
%2 = bitcast %struct.utmp* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @read(i32 %4, %struct.utmp* %1, i32 32)
%10 = icmp eq i32 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %8
%12 = getelementptr inbounds %struct.utmp, %struct.utmp* %1, i64 0, i32 0
%13 = getelementptr inbounds %struct.utmp, %struct.utmp* %1, i64 0, i32 1
%14 = getelementptr inbounds %struct.utmp, %struct.utmp* %1, i64 0, i32 2
%15 = getelementptr inbounds %struct.utmp, %struct.utmp* %1, i64 0, i32 3, i32 0
br label %16
16: ; preds = %11, %25
%17 = load i64, i64* %12
%18 = load i64, i64* @USER_PROCESS
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %13
%22 = load i8*, i8** %14
%23 = call i8* @ctime(i32* %15)
%24 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %22, i8* %23)
br label %25
25: ; preds = %20, %16
%26 = call i32 @read(i32 %4, %struct.utmp* %1, i32 32)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %16
28: ; preds = %25, %8
ret i32 0
}