#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*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ dump(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int getopt(int, char **, char *);
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ undump(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ usage(int);
int main(int argc, char **argv) {
  int c;
  FILE *fp;
  int reverse = 0, forever = 0, oldfmt = 0;
  while ((c = getopt(argc, argv, "froh")) != EOF) {
    switch (c) {
    case 'r':
      reverse = 1;
      break;
    case 'f':
      forever = 1;
      break;
    case 'o':
      oldfmt = 1;
      break;
    case 'h':
      usage(0);
      break;
    default:
      usage(1);
    }
  }
  if (optind < argc) {
    fprintf(stderr, "Utmp %sdump of %s\n", reverse ? "un" : "", argv[optind]);
    if ((fp = fopen(argv[optind], "r")) == NULL) {
      perror("Unable to open file");
      exit(1);
    }
  } else {
    fprintf(stderr, "Utmp %sdump of stdin\n", reverse ? "un" : "");
    fp = stdin;
  }
  if (reverse)
    undump(fp, forever, oldfmt);
  else
    dump(fp, forever, oldfmt);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%eax
je     1248 <main+0xb8>
mov    -0x14(%rbp),%eax
add    $0xffffff9a,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xc,%eax
ja     1239 <main+0xa9>
mov    -0x38(%rbp),%rax
lea    0xe00(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x24(%rbp)
jmp    1243 <main+0xb3>
movl   $0x1,-0x28(%rbp)
jmp    1243 <main+0xb3>
movl   $0x1,-0x2c(%rbp)
jmp    1243 <main+0xb3>
xor    %edi,%edi
call   1060 <usage@plt>
jmp    1243 <main+0xb3>
mov    $0x1,%edi
call   1060 <usage@plt>
jmp    11bb <main+0x2b>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    12e2 <main+0x152>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%ecx
lea    0xe0d(%rip),%rdx
lea    0xdd8(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x10(%rbp),%rax
mov    0x2d52(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x2d32(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd9b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12dd <main+0x14d>
lea    0xd83(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    131f <main+0x18f>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%ecx
lea    0xd85(%rip),%rdx
lea    0xd50(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cd0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     133d <main+0x1ad>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   10b0 <undump@plt>
jmp    134c <main+0x1bc>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1040 <dump@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %edi,%ebp
lea    0xe8d(%rip),%rdx
call   1090 <getopt@plt>
mov    0x2e2d(%rip),%rcx
xor    %r14d,%r14d
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
cmp    (%rcx),%eax
jne    1242 <main+0xb2>
mov    0x2e08(%rip),%rbx
test   %r14d,%r14d
lea    0xea0(%rip),%rax
lea    0xe6b(%rip),%rdx
cmove  %rax,%rdx
movslq (%rbx),%rax
mov    0x2dd9(%rip),%rcx
mov    (%rcx),%edi
cmp    %ebp,%eax
jge    12da <main+0x14a>
mov    0x0(%r13,%rax,8),%rcx
lea    0xe34(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
movslq (%rbx),%rax
mov    0x0(%r13,%rax,8),%rdi
lea    0xe34(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    12f2 <main+0x162>
lea    0xe1e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,0x4(%rsp)
lea    0xde3(%rip),%r12
lea    0xda8(%rip),%r15
movl   $0x0,(%rsp)
xor    %ebx,%ebx
jmp    129c <main+0x10c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
call   1060 <usage@plt>
mov    %ebx,%r14d
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1090 <getopt@plt>
mov    %r14d,%ebx
mov    0x2d4c(%rip),%rcx
cmp    (%rcx),%eax
je     11c9 <main+0x39>
add    $0xffffff9a,%eax
cmp    $0xc,%eax
ja     1270 <main+0xe0>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
mov    $0x1,%r14d
jmp    *%rax
movl   $0x1,(%rsp)
jmp    127a <main+0xea>
nopl   0x0(%rax)
xor    %edi,%edi
jmp    1275 <main+0xe5>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movl   $0x1,0x4(%rsp)
jmp    127a <main+0xea>
lea    0xd84(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%rbp
mov    %rbp,%rdi
test   %r14d,%r14d
je     1308 <main+0x178>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
call   10b0 <undump@plt>
jmp    1314 <main+0x184>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
call   1040 <dump@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"froh\00"
@EOF = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Utmp %sdump of %s\0A\00"
@.str.2 = [3 x i8] c"un\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [20 x i8] c"Unable to open file\00"
@.str.6 = [22 x i8] c"Utmp %sdump of stdin\0A\00"
@stdin = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %26, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %11
%18 = load i32, i32* %6
switch i32 %18, label %24 [
i32 114, label %19
i32 102, label %20
i32 111, label %21
i32 104, label %22
]
19: ; preds = %17
store i32 1, i32* %8
br label %26
20: ; preds = %17
store i32 1, i32* %9
br label %26
21: ; preds = %17
store i32 1, i32* %10
br label %26
22: ; preds = %17
%23 = call i32 @usage(i32 0)
br label %26
24: ; preds = %17
%25 = call i32 @usage(i32 1)
br label %26
26: ; preds = %24, %22, %21, %20, %19
br label %11
27: ; preds = %11
%28 = load i32, i32* @optind
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %54
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%37 = load i8**, i8*** %5
%38 = load i32, i32* @optind
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %41)
%43 = load i8**, i8*** %5
%44 = load i32, i32* @optind
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %48, i32** %7
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %53
50: ; preds = %31
%51 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %31
br label %62
54: ; preds = %27
%55 = load i32, i32* @stderr
%56 = load i32, i32* %8
%57 = icmp ne i32 %56, 0
%58 = zext i1 %57 to i64
%59 = select i1 %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %59)
%61 = load i32*, i32** @stdin
store i32* %61, i32** %7
br label %62
62: ; preds = %54, %53
%63 = load i32, i32* %8
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load i32*, i32** %7
%67 = load i32, i32* %9
%68 = load i32, i32* %10
%69 = call i32 @undump(i32* %66, i32 %67, i32 %68)
br label %75
70: ; preds = %62
%71 = load i32*, i32** %7
%72 = load i32, i32* %9
%73 = load i32, i32* %10
%74 = call i32 @dump(i32* %71, i32 %72, i32 %73)
br label %75
75: ; preds = %70, %65
%76 = load i32*, i32** %7
%77 = call i32 @fclose(i32* %76)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"froh\00"
@EOF = global i32 0
@optind = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Utmp %sdump of %s\0A\00"
@.str.2 = [3 x i8] c"un\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [20 x i8] c"Unable to open file\00"
@.str.6 = [22 x i8] c"Utmp %sdump of stdin\0A\00"
@stdin = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %24, label %6
6: ; preds = %2, %17
%7 = phi i32 [ %21, %17 ], [ %3, %2 ]
%8 = phi i32 [ %20, %17 ], [ 0, %2 ]
%9 = phi i32 [ %19, %17 ], [ 0, %2 ]
%10 = phi i32 [ %18, %17 ], [ 0, %2 ]
switch i32 %7, label %15 [
i32 114, label %17
i32 102, label %11
i32 111, label %12
i32 104, label %13
]
11: ; preds = %6
br label %17
12: ; preds = %6
br label %17
13: ; preds = %6
%14 = tail call i32 @usage(i32 0)
br label %17
15: ; preds = %6
%16 = tail call i32 @usage(i32 1)
br label %17
17: ; preds = %6, %15, %13, %12, %11
%18 = phi i32 [ %10, %15 ], [ %10, %13 ], [ %10, %12 ], [ %10, %11 ], [ 1, %6 ]
%19 = phi i32 [ %9, %15 ], [ %9, %13 ], [ %9, %12 ], [ 1, %11 ], [ %9, %6 ]
%20 = phi i32 [ %8, %15 ], [ %8, %13 ], [ 1, %12 ], [ %8, %11 ], [ %8, %6 ]
%21 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %6
24: ; preds = %17, %2
%25 = phi i32 [ 0, %2 ], [ %18, %17 ]
%26 = phi i32 [ 0, %2 ], [ %19, %17 ]
%27 = phi i32 [ 0, %2 ], [ %20, %17 ]
%28 = load i32, i32* @optind
%29 = icmp slt i32 %28, %0
%30 = load i32, i32* @stderr
%31 = icmp eq i32 %25, 0
%32 = select i1 %31, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
br i1 %29, label %33, label %47
33: ; preds = %24
%34 = sext i32 %28 to i64
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %36)
%38 = load i32, i32* @optind
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %1, i64 %39
%41 = load i8*, i8** %40
%42 = tail call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %50
44: ; preds = %33
%45 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %24
%48 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %32)
%49 = load i32*, i32** @stdin
br label %50
50: ; preds = %33, %47
%51 = phi i32* [ %42, %33 ], [ %49, %47 ]
%52 = icmp eq i32 %25, 0
br i1 %52, label %55, label %53
53: ; preds = %50
%54 = tail call i32 @undump(i32* %51, i32 %26, i32 %27)
br label %57
55: ; preds = %50
%56 = tail call i32 @dump(i32* %51, i32 %26, i32 %27)
br label %57
57: ; preds = %55, %53
%58 = tail call i32 @fclose(i32* %51)
ret i32 0
}