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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char const *, char const *, char const *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
char *getenv(char *);
int /*<<< orphan*/ perror(char const *);
int pipe(int *);
void show(const char *cmd, const char *file) {
  int fds[2];
  pid_t pid;
  if (-1 == pipe(fds)) {
    perror(NULL);
    exit(EXIT_FAILURE);
  }
  if (-1 == (pid = fork())) {
    perror(NULL);
    exit(EXIT_FAILURE);
  } else if (pid > 0) {
    dup2(fds[0], STDIN_FILENO);
    close(fds[1]);
    cmd = NULL != getenv("MANPAGER")
              ? getenv("MANPAGER")
              : (NULL != getenv("PAGER") ? getenv("PAGER") : "more");
    execlp(cmd, cmd, (char *)NULL);
    perror(cmd);
    exit(EXIT_FAILURE);
  }
  dup2(fds[1], STDOUT_FILENO);
  close(fds[0]);
  execlp(cmd, cmd, file, (char *)NULL);
  perror(cmd);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<show>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11bf <show+0x3f>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11ef <show+0x6f>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    12ba <show+0x13a>
mov    -0x18(%rbp),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    0xde7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1241 <show+0xc1>
lea    0xdcd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
jmp    1288 <show+0x108>
lea    0xdbb(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1270 <show+0xf0>
lea    0xda1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
jmp    1280 <show+0x100>
lea    0xd92(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1280 <show+0x100>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1090 <execlp@plt>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12bf <show+0x13f>
mov    -0x14(%rbp),%edi
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1090 <execlp@plt>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<show>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     11a3 <show+0x23>
xor    %eax,%eax
call   10a0 <fork@plt>
cmp    $0xffffffff,%eax
jne    11b8 <show+0x38>
xor    %edi,%edi
call   1070 <perror@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
test   %eax,%eax
jle    1218 <show+0x98>
mov    (%rsp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
lea    0xe23(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1204 <show+0x84>
lea    0xe12(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe09(%rip),%rbx
cmovne %rax,%rbx
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1090 <execlp@plt>
mov    %rbx,%rdi
jmp    11a5 <show+0x25>
mov    0x4(%rsp),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1090 <execlp@plt>
mov    %rbx,%rdi
jmp    11a5 <show+0x25>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@.str = [9 x i8] c"MANPAGER\00"
@.str.1 = [6 x i8] c"PAGER\00"
@.str.2 = [5 x i8] c"more\00"
@STDOUT_FILENO = global i32 0
define void @show(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [2 x i32]
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 -1, %8
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @perror(i8* null)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = call i32 (...) @fork()
store i32 %15, i32* %6
%16 = icmp eq i32 -1, %15
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i32 @perror(i8* null)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %14
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %53
24: ; preds = %21
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%26 = load i32, i32* %25
%27 = load i32, i32* @STDIN_FILENO
%28 = call i32 @dup2(i32 %26, i32 %27)
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%33 = icmp ne i8* null, %32
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %44
36: ; preds = %24
%37 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp ne i8* null, %37
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %42
41: ; preds = %36
br label %42
42: ; preds = %41, %39
%43 = phi i8* [ %40, %39 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %41 ]
br label %44
44: ; preds = %42, %34
%45 = phi i8* [ %35, %34 ], [ %43, %42 ]
store i8* %45, i8** %3
%46 = load i8*, i8** %3
%47 = load i8*, i8** %3
%48 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %46, i8* %47, i8* null)
%49 = load i8*, i8** %3
%50 = call i32 @perror(i8* %49)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %21
br label %54
54: ; preds = %53
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%56 = load i32, i32* %55
%57 = load i32, i32* @STDOUT_FILENO
%58 = call i32 @dup2(i32 %56, i32 %57)
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%60 = load i32, i32* %59
%61 = call i32 @close(i32 %60)
%62 = load i8*, i8** %3
%63 = load i8*, i8** %3
%64 = load i8*, i8** %4
%65 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %62, i8* %63, i8* %64, i8* null)
%66 = load i8*, i8** %3
%67 = call i32 @perror(i8* %66)
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@.str = [9 x i8] c"MANPAGER\00"
@.str.1 = [6 x i8] c"PAGER\00"
@.str.2 = [5 x i8] c"more\00"
@STDOUT_FILENO = global i32 0
define void @show(i8* %0, i8* %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = call i32 @perror(i8* null)
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = call i32 (...) @fork()
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = call i32 @perror(i8* null)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %12
%20 = icmp sgt i32 %13, 0
br i1 %20, label %21, label %40
21: ; preds = %19
%22 = load i32, i32* %5
%23 = load i32, i32* @STDIN_FILENO
%24 = call i32 @dup2(i32 %22, i32 %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %21
%31 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i8* %31, null
%33 = select i1 %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %31
br label %34
34: ; preds = %30, %21
%35 = phi i8* [ %28, %21 ], [ %33, %30 ]
%36 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %35, i8* %35, i8* null)
%37 = call i32 @perror(i8* %35)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %19
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%42 = load i32, i32* %41
%43 = load i32, i32* @STDOUT_FILENO
%44 = call i32 @dup2(i32 %42, i32 %43)
%45 = load i32, i32* %5
%46 = call i32 @close(i32 %45)
%47 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %0, i8* %0, i8* %1, i8* null)
%48 = call i32 @perror(i8* %0)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
}