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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
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(int /*<<< orphan*/);
int read(int, struct utmp *, int);
int /*<<< orphan*/ show_info(struct utmp *);
int main(int argc, char *argv[]) {
  int utmp_fd;
  struct utmp utmp_record;
  int utmp_size = sizeof(utmp_record);
  if ((utmp_fd = open(UTMP_FILE, O_RDONLY)) == -1) {
    perror(UTMP_FILE);
    exit(EXIT_FAILURE);
  }
  while (read(utmp_fd, &utmp_record, utmp_size) == utmp_size) {
    show_info(&utmp_record);
  }
  close(utmp_fd);
  return EXIT_SUCCESS;
}


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,-0x1c(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11bc <main+0x5c>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1070 <perror@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11c1 <main+0x61>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1050 <read@plt>
cmp    -0x1c(%rbp),%eax
jne    11e7 <main+0x87>
lea    -0x18(%rbp),%rdi
call   1030 <show_info@plt>
jmp    11c1 <main+0x61>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
add    $0x20,%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     11d3 <main+0x73>
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>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    (%rbx),%edi
call   1070 <perror@plt>
mov    0x2def(%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
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
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 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* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @UTMP_FILE
%15 = call i32 @perror(i32 %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
br label %19
19: ; preds = %25, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %8
%22 = call i32 @read(i32 %20, %struct.utmp* %7, i32 %21)
%23 = load i32, i32* %8
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @show_info(%struct.utmp* %7)
br label %19
27: ; preds = %19
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* @EXIT_SUCCESS
ret i32 %30
}

LLVM IR (-O2):
%struct.utmp = type { i32 }
@UTMP_FILE = global i32 0
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = 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 %17, label %21
12: ; preds = %2
%13 = load i32, i32* @UTMP_FILE
%14 = tail call i32 @perror(i32 %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %9, %17
%18 = call i32 @show_info(%struct.utmp* %3)
%19 = call i32 @read(i32 %7, %struct.utmp* %3, i32 4)
%20 = icmp eq i32 %19, 4
br i1 %20, label %17, label %21
21: ; preds = %17, %9
%22 = call i32 @close(i32 %7)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}