#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
char *file_type(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ header(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
void do_cat(char *f, int fd) {
  char *extension = file_type(f);
  char *content = "text/plain";
  FILE *fpsock, *fpfile;
  int c;
  if (strcmp(extension, "html") == 0) {
    content = "text/html";
  } else if (strcmp(extension, "gif") == 0) {
    content = "image/gif";
  } else if (strcmp(extension, "jpg") == 0) {
    content = "image/jpeg";
  } else if (strcmp(extension, "jpeg") == 0) {
    content = "image/jpeg";
  }
  fpsock = fdopen(fd, "w");
  fpfile = fopen(f, "r");
  if (fpsock != NULL && fpfile != NULL) {
    header(fpsock, content);
    fprintf(fpsock, "\r\n");
    while ((c = getc(fpfile)) != EOF) {
      putc(c, fpsock);
    }
    fclose(fpfile);
    fclose(fpsock);
  }
  exit(1);
}


x86 assembly (clang, -O0):
<do_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <file_type@plt>
mov    %rax,-0x18(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11f1 <do_cat+0x51>
lea    0xe23(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1279 <do_cat+0xd9>
mov    -0x18(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    121b <do_cat+0x7b>
lea    0xe03(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1274 <do_cat+0xd4>
mov    -0x18(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1245 <do_cat+0xa5>
lea    0xde7(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    126f <do_cat+0xcf>
mov    -0x18(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    126a <do_cat+0xca>
lea    0xdbd(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    126f <do_cat+0xcf>
jmp    1274 <do_cat+0xd4>
jmp    1279 <do_cat+0xd9>
mov    -0xc(%rbp),%edi
lea    0xdab(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1311 <do_cat+0x171>
cmpq   $0x0,-0x30(%rbp)
je     1311 <do_cat+0x171>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <header@plt>
mov    -0x28(%rbp),%rdi
lea    0xd64(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <getc@plt>
mov    %eax,-0x34(%rbp)
mov    0x2d02(%rip),%rcx
cmp    (%rcx),%eax
je     12ff <do_cat+0x15f>
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <putc@plt>
jmp    12d3 <do_cat+0x133>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<do_cat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1090 <file_type@plt>
mov    %rax,%rbx
lea    0xe54(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11d2 <do_cat+0x32>
lea    0xe3b(%rip),%r12
jmp    1230 <do_cat+0x90>
lea    0xe42(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11ef <do_cat+0x4f>
lea    0xe28(%rip),%r12
jmp    1230 <do_cat+0x90>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    120c <do_cat+0x6c>
lea    0xe19(%rip),%r12
jmp    1230 <do_cat+0x90>
lea    0xe16(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
lea    0xdfe(%rip),%rax
lea    0xdd4(%rip),%r12
cmove  %rax,%r12
lea    0xdf7(%rip),%rsi
mov    %ebp,%edi
call   1070 <fdopen@plt>
mov    %rax,%r15
lea    0xde8(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %r15,%r15
je     12c7 <do_cat+0x127>
mov    %rax,%rbx
test   %rax,%rax
je     12c7 <do_cat+0x127>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <header@plt>
lea    0xdc3(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   10c0 <getc@plt>
mov    0x2d58(%rip),%rbp
cmp    0x0(%rbp),%eax
je     12b7 <do_cat+0x117>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%edi
mov    %r15,%rsi
call   1060 <putc@plt>
mov    %rbx,%rdi
call   10c0 <getc@plt>
cmp    0x0(%rbp),%eax
jne    12a0 <do_cat+0x100>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"text/plain\00"
@.str.1 = [5 x i8] c"html\00"
@.str.2 = [10 x i8] c"text/html\00"
@.str.3 = [4 x i8] c"gif\00"
@.str.4 = [10 x i8] c"image/gif\00"
@.str.5 = [4 x i8] c"jpg\00"
@.str.6 = [11 x i8] c"image/jpeg\00"
@.str.7 = [5 x i8] c"jpeg\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [2 x i8] c"r\00"
@.str.10 = [3 x i8] c"\0D\0A\00"
@EOF = global i32 0
define void @do_cat(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i8*, i8** %3
%11 = call i8* @file_type(i8* %10)
store i8* %11, i8** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %6
%12 = load i8*, i8** %5
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %34
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %6
br label %33
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %6
br label %32
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %6
br label %31
31: ; preds = %30, %26
br label %32
32: ; preds = %31, %25
br label %33
33: ; preds = %32, %20
br label %34
34: ; preds = %33, %15
%35 = load i32, i32* %4
%36 = call i32* @fdopen(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i8*, i8** %3
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %38, i32** %8
%39 = load i32*, i32** %7
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %64
41: ; preds = %34
%42 = load i32*, i32** %8
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %64
44: ; preds = %41
%45 = load i32*, i32** %7
%46 = load i8*, i8** %6
%47 = call i32 @header(i32* %45, i8* %46)
%48 = load i32*, i32** %7
%49 = call i32 @fprintf(i32* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
br label %50
50: ; preds = %55, %44
%51 = load i32*, i32** %8
%52 = call i32 @getc(i32* %51)
store i32 %52, i32* %9
%53 = load i32, i32* @EOF
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = load i32, i32* %9
%57 = load i32*, i32** %7
%58 = call i32 @putc(i32 %56, i32* %57)
br label %50
59: ; preds = %50
%60 = load i32*, i32** %8
%61 = call i32 @fclose(i32* %60)
%62 = load i32*, i32** %7
%63 = call i32 @fclose(i32* %62)
br label %64
64: ; preds = %59, %41, %34
%65 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"text/plain\00"
@.str.1 = [5 x i8] c"html\00"
@.str.2 = [10 x i8] c"text/html\00"
@.str.3 = [4 x i8] c"gif\00"
@.str.4 = [10 x i8] c"image/gif\00"
@.str.5 = [4 x i8] c"jpg\00"
@.str.6 = [11 x i8] c"image/jpeg\00"
@.str.7 = [5 x i8] c"jpeg\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [2 x i8] c"r\00"
@.str.10 = [3 x i8] c"\0D\0A\00"
@EOF = global i32 0
define void @do_cat(i8* %0, i32 %1) {
%3 = tail call i8* @file_type(i8* %0)
%4 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0)
br label %16
16: ; preds = %12, %9, %6, %2
%17 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %2 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), %6 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %9 ], [ %15, %12 ]
%18 = tail call i32* @fdopen(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%19 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%20 = icmp ne i32* %18, null
%21 = icmp ne i32* %19, null
%22 = and i1 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %16
%24 = tail call i32 @header(i32* %18, i8* %17)
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i64 2, i64 1, i32* %18)
%26 = tail call i32 @getc(i32* %19)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %35, label %29
29: ; preds = %23, %29
%30 = phi i32 [ %32, %29 ], [ %26, %23 ]
%31 = tail call i32 @putc(i32 %30, i32* %18)
%32 = tail call i32 @getc(i32* %19)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %29
35: ; preds = %29, %23
%36 = tail call i32 @fclose(i32* %19)
%37 = tail call i32 @fclose(i32* %18)
br label %38
38: ; preds = %35, %16
%39 = tail call i32 @exit(i32 1)
unreachable
}