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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ UTMP_FILE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int read(int, struct utmp *, int);
int /*<<< orphan*/ show_info(struct utmp *);
int main() {
  struct utmp current_record;
  int utmpfd;
  int reclen = sizeof(current_record);
  if ((utmpfd = open(UTMP_FILE, O_RDONLY)) == -1) {
    perror(UTMP_FILE);
    exit(1);
  }
  while (read(utmpfd, &current_record, reclen) == reclen)
    show_info(&current_record);
  close(utmpfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11b1 <main+0x51>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11b6 <main+0x56>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%edx
lea    -0x8(%rbp),%rsi
call   1050 <read@plt>
cmp    -0x10(%rbp),%eax
jne    11dc <main+0x7c>
lea    -0x8(%rbp),%rdi
call   1030 <show_info@plt>
jmp    11b6 <main+0x56>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e86(%rip),%rbx
mov    (%rbx),%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
mov    (%rbx),%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.utmp = type { i32 }
@UTMP_FILE = global i32 0
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.utmp
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %4
%5 = load i32, i32* @UTMP_FILE
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i32 %5, i32 %6)
store i32 %7, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @UTMP_FILE
%11 = call i32 @perror(i32 %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
br label %14
14: ; preds = %20, %13
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @read(i32 %15, %struct.utmp* %2, i32 %16)
%18 = load i32, i32* %4
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @show_info(%struct.utmp* %2)
br label %14
22: ; preds = %14
%23 = load i32, i32* %3
%24 = call i32 @close(i32 %23)
ret i32 0
}

LLVM IR (-O2):
%struct.utmp = type { i32 }
@UTMP_FILE = global i32 0
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca %struct.utmp
%2 = bitcast %struct.utmp* %1 to i8*
%3 = load i32, i32* @UTMP_FILE
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i32 %3, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 @read(i32 %5, %struct.utmp* %1, i32 4)
%9 = icmp eq i32 %8, 4
br i1 %9, label %14, label %18
10: ; preds = %0
%11 = load i32, i32* @UTMP_FILE
%12 = tail call i32 @perror(i32 %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7, %14
%15 = call i32 @show_info(%struct.utmp* %1)
%16 = call i32 @read(i32 %5, %struct.utmp* %1, i32 4)
%17 = icmp eq i32 %16, 4
br i1 %17, label %14, label %18
18: ; preds = %14, %7
%19 = call i32 @close(i32 %5)
ret i32 0
}