#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;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ UTMP_FILE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ show_info(struct utmp *);
int /*<<< orphan*/ utmp_close();
struct utmp *utmp_next();
int utmp_open(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct utmp *utbufp;
  int utmp_fd = utmp_open(UTMP_FILE);
  if (utmp_fd == -1) {
    perror(UTMP_FILE);
    exit(EXIT_FAILURE);
  }
  while ((utbufp = utmp_next()) != ((struct utmp *)NULL))
    show_info(utbufp);
  utmp_close();
  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)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1040 <utmp_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ad <main+0x4d>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1070 <perror@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11b2 <main+0x52>
mov    $0x0,%al
call   1060 <utmp_next@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d5 <main+0x75>
mov    -0x18(%rbp),%rdi
call   1030 <show_info@plt>
jmp    11b2 <main+0x52>
mov    $0x0,%al
call   1050 <utmp_close@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e88(%rip),%rbx
mov    (%rbx),%edi
call   1040 <utmp_open@plt>
cmp    $0xffffffff,%eax
je     11a8 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <utmp_next@plt>
test   %rax,%rax
je     1196 <main+0x36>
mov    %rax,%rdi
call   1030 <show_info@plt>
jmp    1180 <main+0x20>
xor    %eax,%eax
call   1050 <utmp_close@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    (%rbx),%edi
call   1070 <perror@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.utmp = type { i32 }
@UTMP_FILE = 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 %struct.utmp*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @UTMP_FILE
%9 = call i32 @utmp_open(i32 %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @UTMP_FILE
%14 = call i32 @perror(i32 %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %21, %17
%19 = call %struct.utmp* (...) @utmp_next()
store %struct.utmp* %19, %struct.utmp** %6
%20 = icmp ne %struct.utmp* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load %struct.utmp*, %struct.utmp** %6
%23 = call i32 @show_info(%struct.utmp* %22)
br label %18
24: ; preds = %18
%25 = call i32 (...) @utmp_close()
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}

LLVM IR (-O2):
%struct.utmp = type { i32 }
@UTMP_FILE = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @UTMP_FILE
%4 = tail call i32 @utmp_open(i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call %struct.utmp* (...) @utmp_next()
%8 = icmp eq %struct.utmp* %7, null
br i1 %8, label %19, label %14
9: ; preds = %2
%10 = load i32, i32* @UTMP_FILE
%11 = tail call i32 @perror(i32 %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %6, %14
%15 = phi %struct.utmp* [ %17, %14 ], [ %7, %6 ]
%16 = tail call i32 @show_info(%struct.utmp* %15)
%17 = tail call %struct.utmp* (...) @utmp_next()
%18 = icmp eq %struct.utmp* %17, null
br i1 %18, label %19, label %14
19: ; preds = %14, %6
%20 = tail call i32 (...) @utmp_close()
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}