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


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    0xdff(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1245 <do_cat+0xa5>
lea    0xde3(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    126f <do_cat+0xcf>
mov    -0x18(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    126a <do_cat+0xca>
lea    0xdc3(%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    0xdb1(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd9f(%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
xor    %eax,%eax
mov    %eax,%esi
call   1030 <header@plt>
mov    -0x28(%rbp),%rdi
lea    0xd6a(%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    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<do_cat>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1090 <file_type@plt>
mov    %rax,%rbp
lea    0xe47(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11fd <do_cat+0x5d>
lea    0xe38(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11fd <do_cat+0x5d>
lea    0xe28(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11fd <do_cat+0x5d>
lea    0xe18(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
lea    0xe0e(%rip),%rsi
mov    %r14d,%edi
call   1070 <fdopen@plt>
mov    %rax,%r14
lea    0xdfe(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %r14,%r14
je     1297 <do_cat+0xf7>
mov    %rax,%rbx
test   %rax,%rax
je     1297 <do_cat+0xf7>
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <header@plt>
lea    0xdda(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   10c0 <getc@plt>
mov    0x2d8b(%rip),%rbp
cmp    0x0(%rbp),%eax
je     1287 <do_cat+0xe7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <putc@plt>
mov    %rbx,%rdi
call   10c0 <getc@plt>
cmp    0x0(%rbp),%eax
jne    1270 <do_cat+0xd0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%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 = [10 x i8] c"image/jpg\00"
@.str.7 = [5 x i8] c"jpeg\00"
@.str.8 = [11 x i8] c"image/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
@EXIT_SUCCESS = 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 ([10 x i8], [10 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.8, 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.9, 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.10, 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 %63
41: ; preds = %34
%42 = load i32*, i32** %8
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %63
44: ; preds = %41
%45 = load i32*, i32** %7
%46 = call i32 @header(i32* %45, i32* null)
%47 = load i32*, i32** %7
%48 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
br label %49
49: ; preds = %54, %44
%50 = load i32*, i32** %8
%51 = call i32 @getc(i32* %50)
store i32 %51, i32* %9
%52 = load i32, i32* @EOF
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = load i32, i32* %9
%56 = load i32*, i32** %7
%57 = call i32 @putc(i32 %55, i32* %56)
br label %49
58: ; preds = %49
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
%61 = load i32*, i32** %8
%62 = call i32 @fclose(i32* %61)
br label %63
63: ; preds = %58, %41, %34
%64 = load i32, i32* @EXIT_SUCCESS
%65 = call i32 @exit(i32 %64)
unreachable
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"html\00"
@.str.3 = [4 x i8] c"gif\00"
@.str.5 = [4 x i8] c"jpg\00"
@.str.7 = [5 x i8] c"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
@EXIT_SUCCESS = 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 %14, 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 %14, 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 %14, 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))
br label %14
14: ; preds = %12, %9, %6, %2
%15 = tail call i32* @fdopen(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%17 = icmp ne i32* %15, null
%18 = icmp ne i32* %16, null
%19 = and i1 %17, %18
br i1 %19, label %20, label %35
20: ; preds = %14
%21 = tail call i32 @header(i32* %15, i32* null)
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i64 2, i64 1, i32* %15)
%23 = tail call i32 @getc(i32* %16)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %32, label %26
26: ; preds = %20, %26
%27 = phi i32 [ %29, %26 ], [ %23, %20 ]
%28 = tail call i32 @putc(i32 %27, i32* %15)
%29 = tail call i32 @getc(i32* %16)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %26
32: ; preds = %26, %20
%33 = tail call i32 @fclose(i32* %15)
%34 = tail call i32 @fclose(i32* %16)
br label %35
35: ; preds = %32, %14
%36 = load i32, i32* @EXIT_SUCCESS
%37 = tail call i32 @exit(i32 %36)
unreachable
}