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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ O_RDONLY;
int dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ execl(char *, char *, char *, char const *, char *);
int /*<<< orphan*/ fork();
char getchar();
char *getenv(char *);
int /*<<< orphan*/ isatty(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
void instructions(void) {
  int input;
  pid_t pid;
  int fd;
  const char *pager;
  int status;
  (void)printf("Would you like instructions (y or n)? ");
  input = getchar();
  while (getchar() != '\n')
    ;
  if (input != 'y')
    return;
  switch (pid = fork()) {
  case 0:
    if (!isatty(1))
      pager = "cat";
    else {
      if (!(pager = getenv("PAGER")) || (*pager == 0))
        pager = "/usr/bin/more";
    }
    if ((fd = open("/usr/share/games/fish.instr", O_RDONLY)) == -1)
      err(1, "open %s", "/usr/share/games/fish.instr");
    if (dup2(fd, 0) == -1)
      err(1, "dup2");
    (void)execl("/bin/sh", "sh", "-c", pager, (char *)NULL);
    err(1, "exec sh -c %s", pager);
  case -1:
    err(1, "fork");
  default:
    (void)waitpid(pid, &status, 0);
    break;
  }
  (void)printf("Hit return to continue...\n");
  while ((input = getchar()) != EOF && input != '\n')
    ;
}


x86 assembly (clang, -O0):
<instructions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe51(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11d9 <instructions+0x39>
jmp    11c1 <instructions+0x21>
cmpl   $0x79,-0x4(%rbp)
je     11e8 <instructions+0x48>
jmp    137a <instructions+0x1da>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
sub    $0xffffffff,%eax
je     130d <instructions+0x16d>
jmp    1205 <instructions+0x65>
mov    -0x20(%rbp),%eax
test   %eax,%eax
jne    1320 <instructions+0x180>
jmp    1215 <instructions+0x75>
mov    $0x1,%edi
call   1040 <isatty@plt>
cmp    $0x0,%eax
jne    1238 <instructions+0x98>
lea    0xdf8(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1272 <instructions+0xd2>
lea    0xdec(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1262 <instructions+0xc2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    126d <instructions+0xcd>
lea    0xdc8(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1272 <instructions+0xd2>
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
lea    0xdbd(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    12ad <instructions+0x10d>
mov    $0x1,%edi
lea    0xdbc(%rip),%rsi
lea    0xd99(%rip),%rdx
mov    $0x0,%al
call   1080 <err@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
cmp    $0xffffffff,%eax
jne    12d3 <instructions+0x133>
mov    $0x1,%edi
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   1080 <err@plt>
mov    -0x18(%rbp),%rcx
lea    0xd8a(%rip),%rdi
lea    0xd88(%rip),%rsi
lea    0xd84(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10b0 <execl@plt>
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1080 <err@plt>
mov    $0x1,%edi
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   1080 <err@plt>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
lea    0xd51(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%ecx
mov    %ecx,-0x4(%rbp)
xor    %eax,%eax
mov    0x2c90(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x21(%rbp)
je     1365 <instructions+0x1c5>
cmpl   $0xa,-0x4(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1375 <instructions+0x1d5>
jmp    137a <instructions+0x1da>
jmp    133a <instructions+0x19a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<instructions>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe41(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %eax,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
jne    11d0 <instructions+0x20>
cmp    $0x79,%bl
jne    1312 <instructions+0x162>
xor    %eax,%eax
call   10d0 <fork@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12c2 <instructions+0x112>
test   %ebx,%ebx
jne    12d5 <instructions+0x125>
mov    $0x1,%edi
call   1050 <isatty@plt>
test   %eax,%eax
je     122e <instructions+0x7e>
lea    0xe18(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1225 <instructions+0x75>
mov    %rax,%r14
cmpb   $0x0,(%rax)
jne    1235 <instructions+0x85>
lea    0xe05(%rip),%r14
jmp    1235 <instructions+0x85>
lea    0xdf2(%rip),%r14
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xdfa(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    126b <instructions+0xbb>
lea    0xe03(%rip),%rsi
lea    0xde0(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1090 <err@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <dup2@plt>
cmp    $0xffffffff,%eax
jne    128c <instructions+0xdc>
lea    0xde3(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1090 <err@plt>
lea    0xdd5(%rip),%rdi
lea    0xdd3(%rip),%rsi
lea    0xdcf(%rip),%rdx
mov    %r14,%rcx
xor    %r8d,%r8d
call   10c0 <execl@plt>
lea    0xdc0(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <err@plt>
lea    0xdb8(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1090 <err@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   10a0 <waitpid@plt>
lea    0xd9c(%rip),%rdi
call   1040 <puts@plt>
mov    0x2cea(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
je     1312 <instructions+0x162>
movsbl %al,%eax
cmp    %eax,(%rbx)
jne    1300 <instructions+0x150>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Would you like instructions (y or n)? \00"
@.str.1 = [4 x i8] c"cat\00"
@.str.2 = [6 x i8] c"PAGER\00"
@.str.3 = [14 x i8] c"/usr/bin/more\00"
@.str.4 = [28 x i8] c"/usr/share/games/fish.instr\00"
@O_RDONLY = global i32 0
@.str.5 = [8 x i8] c"open %s\00"
@.str.6 = [5 x i8] c"dup2\00"
@.str.7 = [8 x i8] c"/bin/sh\00"
@.str.8 = [3 x i8] c"sh\00"
@.str.9 = [3 x i8] c"-c\00"
@.str.10 = [14 x i8] c"exec sh -c %s\00"
@.str.11 = [5 x i8] c"fork\00"
@.str.12 = [27 x i8] c"Hit return to continue...\0A\00"
@EOF = global i32 0
define void @instructions() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = call signext i8 (...) @getchar()
%8 = sext i8 %7 to i32
store i32 %8, i32* %1
br label %9
9: ; preds = %13, %0
%10 = call signext i8 (...) @getchar()
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %14
13: ; preds = %9
br label %9
14: ; preds = %9
%15 = load i32, i32* %1
%16 = icmp ne i32 %15, 121
br i1 %16, label %17, label %18
17: ; preds = %14
br label %69
18: ; preds = %14
%19 = call i32 (...) @fork()
store i32 %19, i32* %2
switch i32 %19, label %53 [
i32 0, label %20
i32 -1, label %51
]
20: ; preds = %18
%21 = call i32 @isatty(i32 1)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %20
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %34
24: ; preds = %20
%25 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %25, i8** %4
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27, %24
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %4
br label %33
33: ; preds = %32, %27
br label %34
34: ; preds = %33, %23
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %35)
store i32 %36, i32* %3
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
%41 = load i32, i32* %3
%42 = call i32 @dup2(i32 %41, i32 0)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
%47 = load i8*, i8** %4
%48 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %47, i8* null)
%49 = load i8*, i8** %4
%50 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %18, %46
%52 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %53
53: ; preds = %18, %51
%54 = load i32, i32* %2
%55 = call i32 @waitpid(i32 %54, i32* %5, i32 0)
br label %56
56: ; preds = %53
%57 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
br label %58
58: ; preds = %68, %56
%59 = call signext i8 (...) @getchar()
%60 = sext i8 %59 to i32
store i32 %60, i32* %1
%61 = load i32, i32* @EOF
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i32, i32* %1
%65 = icmp ne i32 %64, 10
br label %66
66: ; preds = %63, %58
%67 = phi i1 [ false, %58 ], [ %65, %63 ]
br i1 %67, label %68, label %69
68: ; preds = %66
br label %58
69: ; preds = %17, %66
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"Would you like instructions (y or n)? \00"
@.str.1 = [4 x i8] c"cat\00"
@.str.2 = [6 x i8] c"PAGER\00"
@.str.3 = [14 x i8] c"/usr/bin/more\00"
@.str.4 = [28 x i8] c"/usr/share/games/fish.instr\00"
@O_RDONLY = global i32 0
@.str.5 = [8 x i8] c"open %s\00"
@.str.6 = [5 x i8] c"dup2\00"
@.str.7 = [8 x i8] c"/bin/sh\00"
@.str.8 = [3 x i8] c"sh\00"
@.str.9 = [3 x i8] c"-c\00"
@.str.10 = [14 x i8] c"exec sh -c %s\00"
@.str.11 = [5 x i8] c"fork\00"
@EOF = global i32 0
@str = [26 x i8] c"Hit return to continue...\00"
define void @instructions() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar()
br label %5
5: ; preds = %5, %0
%6 = tail call signext i8 (...) @getchar()
%7 = icmp eq i8 %6, 10
br i1 %7, label %8, label %5
8: ; preds = %5
%9 = icmp eq i8 %4, 121
br i1 %9, label %10, label %49
10: ; preds = %8
%11 = tail call i32 (...) @fork()
switch i32 %11, label %39 [
i32 0, label %12
i32 -1, label %37
]
12: ; preds = %10
%13 = tail call i32 @isatty(i32 1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i8, i8* %16
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18, %15
br label %22
22: ; preds = %12, %18, %21
%23 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), %21 ], [ %16, %18 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %12 ]
%24 = load i32, i32* @O_RDONLY
%25 = tail call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = tail call i32 @dup2(i32 %25, i32 0)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %23, i8* null)
%36 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i8* %23)
br label %37
37: ; preds = %10, %34
%38 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %39
39: ; preds = %10, %37
%40 = call i32 @waitpid(i32 %11, i32* %1, i32 0)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %42
42: ; preds = %42, %39
%43 = call signext i8 (...) @getchar()
%44 = sext i8 %43 to i32
%45 = load i32, i32* @EOF
%46 = icmp ne i32 %45, %44
%47 = icmp ne i8 %43, 10
%48 = and i1 %47, %46
br i1 %48, label %42, label %49
49: ; preds = %42, %8
ret void
}