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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
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*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *);
scalar_t__ strcmp(char *, char *);
void do_cat(char *f, int fd) {
  char *extension = file_type(f);
  char content[20] = "text/plain";
  FILE *sock_fp, *file_fp;
  int c;
  if (strcmp(extension, "html") == 0)
    snprintf(content, sizeof(content), "text/html");
  else if (strcmp(extension, "gif") == 0)
    snprintf(content, sizeof(content), "text/gif");
  else if (strcmp(extension, "jpg") == 0)
    snprintf(content, sizeof(content), "text/jpeg");
  else if (strcmp(extension, "jpeg") == 0)
    snprintf(content, sizeof(content), "text/jpeg");
  sock_fp = fdopen(fd, "w");
  file_fp = fopen(f, "r");
  if (sock_fp != NULL && file_fp != NULL) {
    header(sock_fp, content);
    fprintf(sock_fp, "\r\n");
    while ((c = getc(file_fp)) != EOF)
      putc(c, sock_fp);
    fclose(sock_fp);
    fclose(file_fp);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<do_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   10b0 <file_type@plt>
mov    %rax,-0x18(%rbp)
mov    0xe2d(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe2a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe28(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <do_cat+0x6f>
lea    -0x30(%rbp),%rdi
mov    $0x14,%esi
lea    0xdff(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12c5 <do_cat+0x115>
mov    -0x18(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1253 <do_cat+0xa3>
lea    -0x30(%rbp),%rdi
mov    $0x14,%esi
lea    0xdd5(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12c0 <do_cat+0x110>
mov    -0x18(%rbp),%rdi
lea    0xdc9(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1287 <do_cat+0xd7>
lea    -0x30(%rbp),%rdi
mov    $0x14,%esi
lea    0xdae(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12bb <do_cat+0x10b>
mov    -0x18(%rbp),%rdi
lea    0xd9e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12b6 <do_cat+0x106>
lea    -0x30(%rbp),%rdi
mov    $0x14,%esi
lea    0xd7a(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12bb <do_cat+0x10b>
jmp    12c0 <do_cat+0x110>
jmp    12c5 <do_cat+0x115>
mov    -0xc(%rbp),%edi
lea    0xd66(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd54(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     135d <do_cat+0x1ad>
cmpq   $0x0,-0x40(%rbp)
je     135d <do_cat+0x1ad>
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <header@plt>
mov    -0x38(%rbp),%rdi
lea    0xd1f(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   10d0 <getc@plt>
mov    %eax,-0x44(%rbp)
mov    0x2cb6(%rip),%rcx
cmp    (%rcx),%eax
je     134b <do_cat+0x19b>
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1070 <putc@plt>
jmp    131f <do_cat+0x16f>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<do_cat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
call   10a0 <file_type@plt>
mov    %rax,%rbp
movaps 0xe31(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xe37(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f8 <do_cat+0x48>
lea    0xe1e(%rip),%rbx
jmp    1244 <do_cat+0x94>
lea    0xe24(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1215 <do_cat+0x65>
lea    0xe0b(%rip),%rbx
jmp    1244 <do_cat+0x94>
lea    0xe0b(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
lea    0xe00(%rip),%rbx
test   %rax,%rax
je     1244 <do_cat+0x94>
lea    0xdf9(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1254 <do_cat+0xa4>
mov    %rsp,%rdi
mov    $0x14,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0xdda(%rip),%rsi
mov    %r14d,%edi
call   1080 <fdopen@plt>
mov    %rax,%rbp
lea    0xdca(%rip),%rsi
mov    %r15,%rdi
call   1090 <fopen@plt>
test   %rbp,%rbp
je     12e7 <do_cat+0x137>
mov    %rax,%rbx
test   %rax,%rax
je     12e7 <do_cat+0x137>
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1030 <header@plt>
lea    0xda5(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   10d0 <getc@plt>
mov    0x2d33(%rip),%r14
cmp    (%r14),%eax
je     12d7 <do_cat+0x127>
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbp,%rsi
call   1070 <putc@plt>
mov    %rbx,%rdi
call   10d0 <getc@plt>
cmp    (%r14),%eax
jne    12c0 <do_cat+0x110>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

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

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