#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_sec;
};
struct utmp {
  scalar_t__ ut_type;
  char *ut_user;
  TYPE_1__ ut_tv;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ current_record;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ USER_PROCESS;
int /*<<< orphan*/ UTMP_FILE;
int /*<<< orphan*/ close(int);
char *ctime(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
scalar_t__ read(int, struct utmp *, scalar_t__);
int /*<<< orphan*/ stdout;
int main(int argc, char const *argv[]) {
  int fd = open(UTMP_FILE, O_RDONLY);
  struct utmp current_record;
  ssize_t record_len = sizeof(current_record);
  if (fd == -1) {
    perror(UTMP_FILE);
    fprintf(stdout, "Something went wrong\n");
    exit(1);
  }
  while (read(fd, &current_record, record_len) == record_len) {
    if (current_record.ut_type == USER_PROCESS)
      fprintf(stdout, "%s\n", current_record.ut_user);
    fprintf(stdout, "%s\n", ctime(current_record.ut_tv.tv_sec));
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
movq   $0x18,-0x38(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e1 <main+0x71>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1080 <perror@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11e6 <main+0x76>
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rdx
lea    -0x30(%rbp),%rsi
call   1050 <read@plt>
cmp    -0x38(%rbp),%rax
jne    125c <main+0xec>
mov    -0x30(%rbp),%rax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%rax
jne    122f <main+0xbf>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <ctime@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    11e6 <main+0x76>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
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    $0x18,%rsp
mov    0x2e6b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1238 <main+0xc8>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    $0x18,%edx
mov    %eax,%edi
call   1050 <read@plt>
cmp    $0x18,%rax
jne    1220 <main+0xb0>
mov    0x2e23(%rip),%r12
mov    0x2e04(%rip),%r13
lea    0xe4b(%rip),%r14
mov    %rsp,%r15
jmp    1201 <main+0x91>
mov    0x0(%r13),%ebp
mov    0x10(%rsp),%edi
call   1030 <ctime@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x18,%edx
mov    %ebx,%edi
mov    %r15,%rsi
call   1050 <read@plt>
cmp    $0x18,%rax
jne    1220 <main+0xb0>
mov    (%rsp),%rax
cmp    (%r12),%rax
jne    11d0 <main+0x60>
mov    0x0(%r13),%edi
mov    0x8(%rsp),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11d0 <main+0x60>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%edi
call   1080 <perror@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.utmp = type { i64, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@UTMP_FILE = global i32 0
@O_RDONLY = global i32 0
@stdout = global i32 0
@.str = [22 x i8] c"Something went wrong\0A\00"
@USER_PROCESS = global i64 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.utmp
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @UTMP_FILE
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i32 %9, i32 %10)
store i32 %11, i32* %6
store i64 24, i64* %8
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @UTMP_FILE
%16 = call i32 @perror(i32 %15)
%17 = load i32, i32* @stdout
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
br label %21
21: ; preds = %37, %20
%22 = load i32, i32* %6
%23 = load i64, i64* %8
%24 = call i64 @read(i32 %22, %struct.utmp* %7, i64 %23)
%25 = load i64, i64* %8
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %44
27: ; preds = %21
%28 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 0
%29 = load i64, i64* %28
%30 = load i64, i64* @USER_PROCESS
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* @stdout
%34 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 1
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %32, %27
%38 = load i32, i32* @stdout
%39 = getelementptr inbounds %struct.utmp, %struct.utmp* %7, i32 0, i32 2
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i8* @ctime(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %21
44: ; preds = %21
%45 = load i32, i32* %6
%46 = call i32 @close(i32 %45)
ret i32 0
}

LLVM IR (-O2):
%struct.utmp = type { i64, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@UTMP_FILE = global i32 0
@O_RDONLY = global i32 0
@stdout = global i32 0
@.str = [22 x i8] c"Something went wrong\0A\00"
@USER_PROCESS = global i64 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.utmp
%4 = load i32, i32* @UTMP_FILE
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i32 %4, i32 %5)
%7 = bitcast %struct.utmp* %3 to i8*
%8 = icmp eq i32 %6, -1
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = call i64 @read(i32 %6, %struct.utmp* %3, i64 24)
%11 = icmp eq i64 %10, 24
br i1 %11, label %12, label %37
12: ; preds = %9
%13 = getelementptr inbounds %struct.utmp, %struct.utmp* %3, i64 0, i32 0
%14 = getelementptr inbounds %struct.utmp, %struct.utmp* %3, i64 0, i32 1
%15 = getelementptr inbounds %struct.utmp, %struct.utmp* %3, i64 0, i32 2, i32 0
br label %22
16: ; preds = %2
%17 = load i32, i32* @UTMP_FILE
%18 = tail call i32 @perror(i32 %17)
%19 = load i32, i32* @stdout
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %12, %30
%23 = load i64, i64* %13
%24 = load i64, i64* @USER_PROCESS
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* @stdout
%28 = load i8*, i8** %14
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %26, %22
%31 = load i32, i32* @stdout
%32 = load i32, i32* %15
%33 = tail call i8* @ctime(i32 %32)
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = call i64 @read(i32 %6, %struct.utmp* %3, i64 24)
%36 = icmp eq i64 %35, 24
br i1 %36, label %22, label %37
37: ; preds = %30, %9
%38 = tail call i32 @close(i32 %6)
ret i32 0
}