#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fork();
int open(char const *, int /*<<< orphan*/);
scalar_t__ pipe(int *);
scalar_t__ strcmp(char *, char const *);
int strlen(char const *);
FILE *font_open(const char *fname) {
  int nf = strlen(fname);
  if ((nf > 3 && strcmp(".gz", fname + nf - 3) == 0) ||
      (nf > 2 && strcmp(".Z", fname + nf - 2) == 0)) {
    pid_t pid;
    int filedes[2];
    if (pipe(filedes) < 0) {
      return NULL;
    }
    pid = fork();
    if (pid == -1) {
      goto err;
    } else if (pid == 0) {
      int fd0 = open(fname, O_RDONLY);
      if (fd0 < 0) {
        goto err;
      }
      close(filedes[0]);
      close(0);
      close(1);
      dup2(fd0, 0);
      dup2(filedes[1], 1);
      execl("/usr/bin/gunzip", "/usr/bin/gunzip", "-dc", NULL);
      exit(0);
    }
    close(filedes[1]);
    return fdopen(filedes[0], "r");
  err:
    close(filedes[0]);
    close(filedes[1]);
    return NULL;
  } else {
    return fopen(fname, "r");
  }
  return NULL;
}


x86 assembly (clang, -O0):
<font_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jle    11f7 <font_open+0x47>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffd,%rsi
lea    0xe18(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1226 <font_open+0x76>
cmpl   $0x2,-0x14(%rbp)
jle    1320 <font_open+0x170>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffe,%rsi
lea    0xded(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1320 <font_open+0x170>
lea    -0x20(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    1246 <font_open+0x96>
movq   $0x0,-0x8(%rbp)
jmp    1334 <font_open+0x184>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    125f <font_open+0xaf>
jmp    1303 <font_open+0x153>
cmpl   $0x0,-0x18(%rbp)
jne    12de <font_open+0x12e>
mov    -0x10(%rbp),%rdi
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    128d <font_open+0xdd>
jmp    1303 <font_open+0x153>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
xor    %esi,%esi
call   1040 <dup2@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
lea    0xd43(%rip),%rsi
lea    0xd4c(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10c0 <execl@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    12e3 <font_open+0x133>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
lea    0xd26(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x8(%rbp)
jmp    1334 <font_open+0x184>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    1334 <font_open+0x184>
mov    -0x10(%rbp),%rdi
lea    0xcf0(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<font_open>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x4,%eax
jl     11de <font_open+0x2e>
mov    %eax,%ebx
lea    (%r14,%rbx,1),%rsi
add    $0xfffffffffffffffd,%rsi
lea    0xe2e(%rip),%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11e8 <font_open+0x38>
jmp    1217 <font_open+0x67>
mov    $0x3,%ebx
cmp    $0x3,%eax
jne    1201 <font_open+0x51>
lea    (%r14,%rbx,1),%rsi
add    $0xfffffffffffffffe,%rsi
lea    0xe0d(%rip),%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1217 <font_open+0x67>
lea    0xe13(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <fopen@plt>
mov    %rsp,%rdi
call   1060 <pipe@plt>
test   %rax,%rax
js     125a <font_open+0xaa>
xor    %eax,%eax
call   10d0 <fork@plt>
cmp    $0xffffffff,%eax
je     1249 <font_open+0x99>
test   %eax,%eax
jne    125e <font_open+0xae>
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <open@plt>
test   %eax,%eax
jns    127e <font_open+0xce>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1276 <font_open+0xc6>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
mov    (%rsp),%edi
lea    0xdaa(%rip),%rsi
call   1080 <fdopen@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %eax,%ebx
mov    (%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <dup2@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
lea    0xd50(%rip),%rdi
lea    0xd59(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   10c0 <execl@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c".gz\00"
@.str.1 = [3 x i8] c".Z\00"
@O_RDONLY = global i32 0
@.str.2 = [16 x i8] c"/usr/bin/gunzip\00"
@.str.3 = [4 x i8] c"-dc\00"
@.str.4 = [2 x i8] c"r\00"
define i32* @font_open(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i32]
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 3
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 -3
%18 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %31, label %20
20: ; preds = %12, %1
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 2
br i1 %22, label %23, label %79
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 -2
%29 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %79
31: ; preds = %23, %12
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%33 = call i64 @pipe(i32* %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i32* null, i32** %2
br label %82
36: ; preds = %31
%37 = call i32 (...) @fork()
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %41
40: ; preds = %36
br label %72
41: ; preds = %36
%42 = load i32, i32* %5
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %64
44: ; preds = %41
%45 = load i8*, i8** %3
%46 = load i32, i32* @O_RDONLY
%47 = call i32 @open(i8* %45, i32 %46)
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %44
br label %72
51: ; preds = %44
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
%55 = call i32 @close(i32 0)
%56 = call i32 @close(i32 1)
%57 = load i32, i32* %7
%58 = call i32 @dup2(i32 %57, i32 0)
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%60 = load i32, i32* %59
%61 = call i32 @dup2(i32 %60, i32 1)
%62 = call i32 @execl(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* null)
%63 = call i32 @exit(i32 0)
unreachable
64: ; preds = %41
br label %65
65: ; preds = %64
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%67 = load i32, i32* %66
%68 = call i32 @close(i32 %67)
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%70 = load i32, i32* %69
%71 = call i32* @fdopen(i32 %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %71, i32** %2
br label %82
72: ; preds = %50, %40
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%74 = load i32, i32* %73
%75 = call i32 @close(i32 %74)
%76 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%77 = load i32, i32* %76
%78 = call i32 @close(i32 %77)
store i32* null, i32** %2
br label %82
79: ; preds = %23, %20
%80 = load i8*, i8** %3
%81 = call i32* @fopen(i8* %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %81, i32** %2
br label %82
82: ; preds = %79, %72, %65, %35
%83 = load i32*, i32** %2
ret i32* %83
}

LLVM IR (-O2):
@.str = [4 x i8] c".gz\00"
@.str.1 = [3 x i8] c".Z\00"
@O_RDONLY = global i32 0
@.str.2 = [16 x i8] c"/usr/bin/gunzip\00"
@.str.3 = [4 x i8] c"-dc\00"
@.str.4 = [2 x i8] c"r\00"
define noalias i32* @font_open(i8* %0) {
%2 = alloca [2 x i32]
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 3
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = zext i32 %3 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 -3
%9 = tail call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %19, label %13
11: ; preds = %1
%12 = icmp eq i32 %3, 3
br i1 %12, label %13, label %55
13: ; preds = %11, %5
%14 = phi i64 [ %6, %5 ], [ 3, %11 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -2
%17 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %55
19: ; preds = %13, %5
%20 = bitcast [2 x i32]* %2 to i8*
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%22 = call i64 @pipe(i32* %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %53, label %24
24: ; preds = %19
%25 = call i32 (...) @fork()
switch i32 %25, label %41 [
i32 -1, label %47
i32 0, label %26
]
26: ; preds = %24
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %0, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %47, label %30
30: ; preds = %26
%31 = load i32, i32* %21
%32 = call i32 @close(i32 %31)
%33 = call i32 @close(i32 0)
%34 = call i32 @close(i32 1)
%35 = call i32 @dup2(i32 %28, i32 0)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%37 = load i32, i32* %36
%38 = call i32 @dup2(i32 %37, i32 1)
%39 = call i32 @execl(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* null)
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %24
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%43 = load i32, i32* %42
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* %21
%46 = call i32* @fdopen(i32 %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %53
47: ; preds = %26, %24
%48 = load i32, i32* %21
%49 = call i32 @close(i32 %48)
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
br label %53
53: ; preds = %19, %47, %41
%54 = phi i32* [ null, %47 ], [ %46, %41 ], [ null, %19 ]
br label %57
55: ; preds = %13, %11
%56 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %55, %53
%58 = phi i32* [ %54, %53 ], [ %56, %55 ]
ret i32* %58
}