#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*/ EINTR;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ WEXITSTATUS(int);
int /*<<< orphan*/ _exit(int);
int dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execl(char *, char *, char *, char const *, char *);
int /*<<< orphan*/ exit(int);
char *getenv(char *);
int /*<<< orphan*/ isatty(int);
int open(char *, int /*<<< orphan*/);
int vfork();
int waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *, ...);
void instructions() {
  int pstat;
  int fd;
  pid_t pid;
  const char *path;
  switch (pid = vfork()) {
  case -1:
    err(1, "vfork");
  case 0:
    if (!isatty(1))
      path = "cat";
    else {
      if (!(path = getenv("PAGER")) || (*path == 0))
        path = "/usr/bin/pager";
    }
    if ((fd = open("/usr/share/games/bsdgames/cribbage.instr", O_RDONLY)) ==
        -1) {
      warn("open %s", "/usr/share/games/bsdgames/cribbage.instr");
      _exit(1);
    }
    if (dup2(fd, 0) == -1) {
      warn("dup2");
      _exit(1);
    }
    execl("/bin/sh", "sh", "-c", path, (char *)NULL);
    warn(NULL);
    _exit(1);
  default:
    do {
      pid = waitpid(pid, &pstat, 0);
    } while (pid == -1 && errno == EINTR);
    if (pid == -1 || WEXITSTATUS(pstat))
      exit(1);
  }
}


x86 assembly (clang, -O0):
<instructions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
call   10c0 <vfork@plt>
mov    %eax,-0xc(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     11f3 <instructions+0x33>
jmp    11e3 <instructions+0x23>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     1204 <instructions+0x44>
jmp    1304 <instructions+0x144>
mov    $0x1,%edi
lea    0xe01(%rip),%rsi
call   1080 <err@plt>
mov    $0x1,%edi
call   1060 <isatty@plt>
cmp    $0x0,%eax
jne    1227 <instructions+0x67>
lea    0xde8(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <instructions+0xa1>
lea    0xddc(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1251 <instructions+0x91>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    125c <instructions+0x9c>
lea    0xdb8(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <instructions+0xa1>
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
lea    0xdae(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    12a1 <instructions+0xe1>
lea    0xdbf(%rip),%rdi
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1050 <warn@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1070 <dup2@plt>
cmp    $0xffffffff,%eax
jne    12cc <instructions+0x10c>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <warn@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    -0x18(%rbp),%rcx
lea    0xd7e(%rip),%rdi
lea    0xd7c(%rip),%rsi
lea    0xd78(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10e0 <execl@plt>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x0,%al
call   1050 <warn@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
jmp    1309 <instructions+0x149>
mov    -0xc(%rbp),%edi
lea    -0x4(%rbp),%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0xc(%rbp)
mov    %al,-0x1d(%rbp)
jne    1341 <instructions+0x181>
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
mov    0x2c97(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1309 <instructions+0x149>
cmpl   $0xffffffff,-0xc(%rbp)
je     1367 <instructions+0x1a7>
mov    -0x4(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     1371 <instructions+0x1b1>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1376 <instructions+0x1b6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<instructions>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
call   10c0 <vfork@plt>
cmp    $0xffffffff,%eax
je     1266 <instructions+0xa6>
test   %eax,%eax
je     1277 <instructions+0xb7>
mov    %eax,%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
cmp    $0xffffffff,%eax
sete   %al
jne    123e <instructions+0x7e>
mov    0x2dd9(%rip),%r15
mov    0x2dca(%rip),%r12
mov    (%r12),%ecx
cmp    %ecx,(%r15)
jne    123e <instructions+0x7e>
mov    $0xffffffff,%r14d
lea    0xc(%rsp),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   10a0 <waitpid@plt>
cmp    $0xffffffff,%eax
sete   %al
jne    123e <instructions+0x7e>
mov    (%r12),%ecx
cmp    %ecx,(%r15)
je     1220 <instructions+0x60>
test   %al,%al
jne    125c <instructions+0x9c>
mov    0xc(%rsp),%edi
call   1090 <WEXITSTATUS@plt>
test   %eax,%eax
jne    125c <instructions+0x9c>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd93(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
mov    $0x1,%edi
call   1060 <isatty@plt>
test   %eax,%eax
jne    128e <instructions+0xce>
lea    0xd7a(%rip),%rbx
jmp    12ae <instructions+0xee>
lea    0xd75(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12a7 <instructions+0xe7>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    12ae <instructions+0xee>
lea    0xd62(%rip),%rbx
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
lea    0xd61(%rip),%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
jne    12e7 <instructions+0x127>
lea    0xd79(%rip),%rdi
lea    0xd49(%rip),%rsi
xor    %eax,%eax
call   1050 <warn@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1070 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1300 <instructions+0x140>
lea    0xd54(%rip),%rdi
xor    %eax,%eax
jmp    132c <instructions+0x16c>
lea    0xd4e(%rip),%rdi
lea    0xd4c(%rip),%rsi
lea    0xd48(%rip),%rdx
xor    %r14d,%r14d
mov    %r14d,%ebp
mov    %rbx,%rcx
mov    %rbp,%r8
call   10e0 <execl@plt>
mov    %r14d,%eax
mov    %rbp,%rdi
call   1050 <warn@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"vfork\00"
@.str.1 = [4 x i8] c"cat\00"
@.str.2 = [6 x i8] c"PAGER\00"
@.str.3 = [15 x i8] c"/usr/bin/pager\00"
@.str.4 = [41 x i8] c"/usr/share/games/bsdgames/cribbage.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"
@errno = global i32 0
@EINTR = global i32 0
define void @instructions() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = call i32 @vfork()
store i32 %5, i32* %3
switch i32 %5, label %41 [
i32 -1, label %6
i32 0, label %8
]
6: ; preds = %0
%7 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %0, %6
%9 = call i32 @isatty(i32 1)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %8
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %22
12: ; preds = %8
%13 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %13, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15, %12
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8** %4
br label %21
21: ; preds = %20, %15
br label %22
22: ; preds = %21, %11
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %23)
store i32 %24, i32* %2
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @_exit(i32 1)
unreachable
29: ; preds = %22
%30 = load i32, i32* %2
%31 = call i32 @dup2(i32 %30, i32 0)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%35 = call i32 @_exit(i32 1)
unreachable
36: ; preds = %29
%37 = load i8*, i8** %4
%38 = 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* %37, i8* null)
%39 = call i32 (i8*, ...) @warn(i8* null)
%40 = call i32 @_exit(i32 1)
unreachable
41: ; preds = %0
br label %42
42: ; preds = %52, %41
%43 = load i32, i32* %3
%44 = call i32 @waitpid(i32 %43, i32* %1, i32 0)
store i32 %44, i32* %3
br label %45
45: ; preds = %42
%46 = load i32, i32* %3
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* @errno
%50 = load i32, i32* @EINTR
%51 = icmp eq i32 %49, %50
br label %52
52: ; preds = %48, %45
%53 = phi i1 [ false, %45 ], [ %51, %48 ]
br i1 %53, label %42, label %54
54: ; preds = %52
%55 = load i32, i32* %3
%56 = icmp eq i32 %55, -1
br i1 %56, label %61, label %57
57: ; preds = %54
%58 = load i32, i32* %1
%59 = call i32 @WEXITSTATUS(i32 %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %57, %54
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %57
br label %64
64: ; preds = %63
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"vfork\00"
@.str.1 = [4 x i8] c"cat\00"
@.str.2 = [6 x i8] c"PAGER\00"
@.str.3 = [15 x i8] c"/usr/bin/pager\00"
@.str.4 = [41 x i8] c"/usr/share/games/bsdgames/cribbage.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"
@errno = global i32 0
@EINTR = global i32 0
define void @instructions() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @vfork()
switch i32 %3, label %4 [
i32 -1, label %11
i32 0, label %13
]
4: ; preds = %0
%5 = call i32 @waitpid(i32 %3, i32* %1, i32 0)
%6 = icmp eq i32 %5, -1
%7 = load i32, i32* @errno
%8 = load i32, i32* @EINTR
%9 = icmp eq i32 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %41, label %48
11: ; preds = %0
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %0, %11
%14 = call i32 @isatty(i32 1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %13
%17 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i8, i8* %17
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19, %16
br label %23
23: ; preds = %13, %19, %22
%24 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %22 ], [ %17, %19 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %13 ]
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @_exit(i32 1)
unreachable
31: ; preds = %23
%32 = call i32 @dup2(i32 %26, i32 0)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%36 = call i32 @_exit(i32 1)
unreachable
37: ; preds = %31
%38 = 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* %24, i8* null)
%39 = call i32 (i8*, ...) @warn(i8* null)
%40 = call i32 @_exit(i32 1)
unreachable
41: ; preds = %4, %41
%42 = call i32 @waitpid(i32 -1, i32* %1, i32 0)
%43 = icmp eq i32 %42, -1
%44 = load i32, i32* @errno
%45 = load i32, i32* @EINTR
%46 = icmp eq i32 %44, %45
%47 = select i1 %43, i1 %46, i1 false
br i1 %47, label %41, label %48
48: ; preds = %41, %4
%49 = phi i1 [ %6, %4 ], [ %43, %41 ]
br i1 %49, label %54, label %50
50: ; preds = %48
%51 = load i32, i32* %1
%52 = call i32 @WEXITSTATUS(i32 %51)
%53 = icmp eq i32 %52, 0
br i1 %53, label %56, label %54
54: ; preds = %50, %48
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %50
ret void
}