#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 */
typedef int /*<<< orphan*/ utbuf;
struct utmp {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ UTMP_FILE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, struct utmp *, int);
int /*<<< orphan*/ show_info(struct utmp *);
int main(int argc, char *argv[]) {
  struct utmp utbuf;
  int utmpfd;
  int reclen = sizeof(utbuf);
  if ((utmpfd = open(UTMP_FILE, O_RDONLY)) == -1) {
    perror("open UTMP_FILE failed:");
    exit(EXIT_FAILURE);
  }
  while (read(utmpfd, &utbuf, reclen) == reclen)
    show_info(&utbuf);
  close(utmpfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x20(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11ba <main+0x5a>
lea    0xe59(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11bf <main+0x5f>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1050 <read@plt>
cmp    -0x20(%rbp),%eax
jne    11e5 <main+0x85>
lea    -0x18(%rbp),%rdi
call   1030 <show_info@plt>
jmp    11bf <main+0x5f>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11cc <main+0x6c>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    11bc <main+0x5c>
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <show_info@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
je     11a0 <main+0x40>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe2d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.utmp = type { i32 }
@UTMP_FILE = global i32 0
@O_RDONLY = global i32 0
@.str = [23 x i8] c"open UTMP_FILE failed:\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.utmp
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %8
%9 = load i32, i32* @UTMP_FILE
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i32 %9, i32 %10)
store i32 %11, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %24, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = call i32 @read(i32 %19, %struct.utmp* %6, i32 %20)
%22 = load i32, i32* %8
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @show_info(%struct.utmp* %6)
br label %18
26: ; preds = %18
%27 = load i32, i32* %7
%28 = call i32 @close(i32 %27)
ret i32 0
}

LLVM IR (-O2):
%struct.utmp = type { i32 }
@UTMP_FILE = global i32 0
@O_RDONLY = global i32 0
@.str = [23 x i8] c"open UTMP_FILE failed:\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.utmp
%4 = bitcast %struct.utmp* %3 to i8*
%5 = load i32, i32* @UTMP_FILE
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i32 %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32 @read(i32 %7, %struct.utmp* %3, i32 4)
%11 = icmp eq i32 %10, 4
br i1 %11, label %16, label %20
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %9, %16
%17 = call i32 @show_info(%struct.utmp* %3)
%18 = call i32 @read(i32 %7, %struct.utmp* %3, i32 4)
%19 = icmp eq i32 %18, 4
br i1 %19, label %16, label %20
20: ; preds = %16, %9
%21 = call i32 @close(i32 %7)
ret i32 0
}