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

/* Variables and functions */
int /*<<< orphan*/ execl(char *, char *, char const *, void *);
int fork();
char *getenv(char *);
int /*<<< orphan*/ wait(int *);
int util_viewFile(const char *name) {
  char *pager = getenv("PAGER");
  if (pager == NULL) {
    pager = "/bin/less";
  }
  int pid = fork();
  if (pid == 0) {
    execl(pager, pager, name, (void *)NULL);
  } else if (pid == -1) {
    return 1;
  } else {
    int status;
    wait(&status);
  }
  return 0;
}


x86 assembly (clang, -O0):
<util_viewFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1172 <util_viewFile+0x32>
lea    0xe98(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11a0 <util_viewFile+0x60>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <execl@plt>
jmp    11c4 <util_viewFile+0x84>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11b6 <util_viewFile+0x76>
movl   $0x1,-0x4(%rbp)
jmp    11cb <util_viewFile+0x8b>
lea    -0x20(%rbp),%rdi
call   1050 <wait@plt>
jmp    11c4 <util_viewFile+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_viewFile>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     1185 <util_viewFile+0x45>
test   %eax,%eax
jne    118c <util_viewFile+0x4c>
test   %rbx,%rbx
lea    0xe96(%rip),%rdi
cmovne %rbx,%rdi
xor    %ebx,%ebx
mov    %rdi,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1040 <execl@plt>
jmp    1198 <util_viewFile+0x58>
mov    $0x1,%ebx
jmp    1198 <util_viewFile+0x58>
lea    0x4(%rsp),%rdi
call   1050 <wait@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"PAGER\00"
@.str.1 = [10 x i8] c"/bin/less\00"
define i32 @util_viewFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %11
11: ; preds = %10, %1
%12 = call i32 (...) @fork()
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = call i32 @execl(i8* %16, i8* %17, i8* %18, i8* null)
br label %27
20: ; preds = %11
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 1, i32* %2
br label %28
24: ; preds = %20
%25 = call i32 @wait(i32* %6)
br label %26
26: ; preds = %24
br label %27
27: ; preds = %26, %15
store i32 0, i32* %2
br label %28
28: ; preds = %27, %23
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [6 x i8] c"PAGER\00"
@.str.1 = [10 x i8] c"/bin/less\00"
define i32 @util_viewFile(i8* %0) {
%2 = alloca i32
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (...) @fork()
switch i32 %4, label %9 [
i32 0, label %5
i32 -1, label %12
]
5: ; preds = %1
%6 = icmp eq i8* %3, null
%7 = select i1 %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %3
%8 = tail call i32 @execl(i8* %7, i8* %7, i8* %0, i8* null)
br label %12
9: ; preds = %1
%10 = bitcast i32* %2 to i8*
%11 = call i32 @wait(i32* %2)
br label %12
12: ; preds = %5, %9, %1
%13 = phi i32 [ 1, %1 ], [ 0, %9 ], [ 0, %5 ]
ret i32 %13
}