#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 EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ UTMP_FILE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ get_info(struct utmp *);
int open(int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, struct utmp *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  struct utmp utbuf;
  int utmpfd;
  if ((utmpfd = open(UTMP_FILE, O_RDONLY)) < 0) {
    fprintf(stderr, "Err.(%s) open() failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  while (read(utmpfd, &utbuf, sizeof(utbuf)) == sizeof(utbuf))
    get_info(&utbuf);
  close(utmpfd);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11dc <main+0x6c>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe37(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11e1 <main+0x71>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cltq
cmp    $0x4,%rax
jne    120c <main+0x9c>
lea    -0x8(%rbp),%rdi
call   1030 <get_info@plt>
jmp    11e1 <main+0x71>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11e3 <main+0x73>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    11cc <main+0x5c>
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <get_info@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
je     11b0 <main+0x40>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2de6(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdff(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2dae(%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
@stderr = global i32 0
@.str = [24 x i8] c"Err.(%s) open() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.utmp
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @UTMP_FILE
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i32 %4, i32 %5)
store i32 %6, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
br label %16
16: ; preds = %21, %15
%17 = load i32, i32* %3
%18 = call i32 @read(i32 %17, %struct.utmp* %2, i32 4)
%19 = sext i32 %18 to i64
%20 = icmp eq i64 %19, 4
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @get_info(%struct.utmp* %2)
br label %16
23: ; preds = %16
%24 = load i32, i32* %3
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}

LLVM IR (-O2):
%struct.utmp = type { i32 }
@UTMP_FILE = global i32 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Err.(%s) open() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = 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 slt i32 %5, 0
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 %17, label %21
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %7, %17
%18 = call i32 @get_info(%struct.utmp* %1)
%19 = call i32 @read(i32 %5, %struct.utmp* %1, i32 4)
%20 = icmp eq i32 %19, 4
br i1 %20, label %17, label %21
21: ; preds = %17, %7
%22 = call i32 @close(i32 %5)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}