#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ *popen(char const *, char const *);
int /*<<< orphan*/ stderr;
FILE *Popen(const char *fn, const char *mode) {
  FILE *result;
  result = popen(fn, mode);
  if (result == NULL) {
    fprintf(stderr, "Couldn't open file '%s' for ", fn);
    switch (mode[0]) {
    case 'r':
      fprintf(stderr, "reading");
      break;
    case 'w':
      fprintf(stderr, "writing");
      break;
    case 'a':
      fprintf(stderr, "appending");
      break;
    default:
      fprintf(stderr, "unknown operation code '%c'", mode[0]);
      break;
    }
    fprintf(stderr, ". Bye!\n");
    exit(-1);
  }
  return (result);
}


x86 assembly (clang, -O0):
<Popen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1244 <Popen+0x114>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe90(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x61,%eax
je     11e9 <Popen+0xb9>
jmp    118f <Popen+0x5f>
mov    -0x1c(%rbp),%eax
sub    $0x72,%eax
je     11b1 <Popen+0x81>
jmp    11a0 <Popen+0x70>
mov    -0x1c(%rbp),%eax
sub    $0x77,%eax
je     11cd <Popen+0x9d>
jmp    1205 <Popen+0xd5>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1223 <Popen+0xf3>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1223 <Popen+0xf3>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1223 <Popen+0xf3>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Popen>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <popen@plt>
test   %rax,%rax
je     114b <Popen+0x1b>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e8e(%rip),%r15
mov    (%r15),%edi
lea    0xea4(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
movsbl (%r14),%edx
cmp    $0x61,%edx
je     1185 <Popen+0x55>
cmp    $0x77,%edx
je     1191 <Popen+0x61>
cmp    $0x72,%edx
jne    11a4 <Popen+0x74>
mov    (%r15),%edi
lea    0xe9a(%rip),%rsi
jmp    119b <Popen+0x6b>
mov    (%r15),%edi
lea    0xe9e(%rip),%rsi
jmp    119b <Popen+0x6b>
mov    (%r15),%edi
lea    0xe8a(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11b5 <Popen+0x85>
mov    (%r15),%edi
lea    0xe89(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
lea    0xe94(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Couldn't open file '%s' for \00"
@.str.1 = [8 x i8] c"reading\00"
@.str.2 = [8 x i8] c"writing\00"
@.str.3 = [10 x i8] c"appending\00"
@.str.4 = [28 x i8] c"unknown operation code '%c'\00"
@.str.5 = [8 x i8] c". Bye!\0A\00"
define i32* @Popen(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i32* @popen(i8* %6, i8* %7)
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %39
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
switch i32 %18, label %28 [
i32 114, label %19
i32 119, label %22
i32 97, label %25
]
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %35
22: ; preds = %11
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %35
25: ; preds = %11
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %35
28: ; preds = %11
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %28, %25, %22, %19
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %2
%40 = load i32*, i32** %5
ret i32* %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Couldn't open file '%s' for \00"
@.str.1 = [8 x i8] c"reading\00"
@.str.2 = [8 x i8] c"writing\00"
@.str.3 = [10 x i8] c"appending\00"
@.str.4 = [28 x i8] c"unknown operation code '%c'\00"
@.str.5 = [8 x i8] c". Bye!\0A\00"
define noalias i32* @Popen(i8* %0, i8* nocapture %1) {
%3 = tail call i32* @popen(i8* %0, i8* %1)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %26
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i8, i8* %1
%9 = sext i8 %8 to i32
switch i32 %9, label %19 [
i32 114, label %10
i32 119, label %13
i32 97, label %16
]
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %22
13: ; preds = %5
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %22
16: ; preds = %5
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %22
19: ; preds = %5
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %9)
br label %22
22: ; preds = %19, %16, %13, %10
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%25 = tail call i32 @exit(i32 -1)
unreachable
26: ; preds = %2
ret i32* %3
}