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


x86 assembly (clang, -O0):
<resp_do_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <get_filename_extension@plt>
mov    %rax,-0x20(%rbp)
lea    0xe4d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11e1 <resp_do_cat+0x51>
lea    0xe33(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1269 <resp_do_cat+0xd9>
mov    -0x20(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    120b <resp_do_cat+0x7b>
lea    0xe13(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1264 <resp_do_cat+0xd4>
mov    -0x20(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1235 <resp_do_cat+0xa5>
lea    0xdf2(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    125f <resp_do_cat+0xcf>
mov    -0x20(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    125a <resp_do_cat+0xca>
lea    0xdd1(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    125f <resp_do_cat+0xcf>
jmp    1264 <resp_do_cat+0xd4>
jmp    1269 <resp_do_cat+0xd9>
mov    -0x14(%rbp),%edi
lea    0xdbe(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdac(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     130d <resp_do_cat+0x17d>
cmpq   $0x0,-0x38(%rbp)
je     130d <resp_do_cat+0x17d>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <pack_header@plt>
mov    -0x30(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d12(%rip),%rcx
cmp    (%rcx),%eax
je     12ef <resp_do_cat+0x15f>
mov    -0x18(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <putc@plt>
jmp    12c3 <resp_do_cat+0x133>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1314 <resp_do_cat+0x184>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resp_do_cat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1080 <get_filename_extension@plt>
mov    %rax,%rbx
lea    0xe64(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1207 <resp_do_cat+0x77>
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1210 <resp_do_cat+0x80>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1219 <resp_do_cat+0x89>
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
lea    0xe2d(%rip),%rax
lea    0xdff(%rip),%r12
cmove  %rax,%r12
jmp    1220 <resp_do_cat+0x90>
lea    0xdfd(%rip),%r12
jmp    1220 <resp_do_cat+0x90>
lea    0xdfe(%rip),%r12
jmp    1220 <resp_do_cat+0x90>
lea    0xdfe(%rip),%r12
lea    0xe0a(%rip),%rsi
mov    %ebp,%edi
call   1070 <fdopen@plt>
mov    %rax,%r15
lea    0xdfb(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    $0x1,%eax
test   %r15,%r15
je     12b9 <resp_do_cat+0x129>
test   %rbx,%rbx
je     12b9 <resp_do_cat+0x129>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <pack_header@plt>
lea    0xdd1(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    0x2d63(%rip),%rbp
cmp    0x0(%rbp),%eax
je     12a7 <resp_do_cat+0x117>
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %r15,%rsi
call   1050 <putc@plt>
mov    %rbx,%rdi
call   10b0 <getc@plt>
cmp    0x0(%rbp),%eax
jne    1290 <resp_do_cat+0x100>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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 = [9 x i8] c"text/gif\00"
@.str.5 = [4 x i8] c"jpg\00"
@.str.6 = [9 x i8] c"text/jpg\00"
@.str.7 = [5 x i8] c"jpeg\00"
@.str.8 = [10 x i8] c"text/jpeg\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [2 x i8] c"r\00"
@.str.11 = [3 x i8] c"\0D\0A\00"
@EOF = global i32 0
define i32 @resp_do_cat(i8* %0, i32 %1) {
%3 = tail call i8* @get_filename_extension(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 ([10 x i8], [10 x i8]* @.str.8, 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 ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %6 ], [ getelementptr inbounds ([9 x i8], [9 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.9, i64 0, i64 0))
%19 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, 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 @pack_header(i32* %18, i8* %17)
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, 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 = %16, %35
%39 = phi i32 [ 0, %35 ], [ 1, %16 ]
ret i32 %39
}