#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 */

/* Variables and functions */
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strrchr(char const *, char);
void transmit_headers(int s, const char *path, int size) {
  char buf[9000];
  char *ext;
  char *type;
  if ((ext = strrchr(path, '.')) != NULL) {
    if (strcmp(ext, ".jpg") == 0)
      type = "image/jpeg";
    else
      type = "text/html";
  }
  sprintf(buf, "HTTP/1.0 200 OK\r\n");
  send(s, buf, strlen(buf), 0);
  sprintf(buf, "Connection: keep-alive\r\n");
  send(s, buf, strlen(buf), 0);
  sprintf(buf, "Content-Type: %s\r\n", type);
  send(s, buf, strlen(buf), 0);
  sprintf(buf, "Content-Length: %d\r\n", size);
  send(s, buf, strlen(buf), 0);
  sprintf(buf, "Server: cs360httpd/1.0 (Unix)\r\n");
  send(s, buf, strlen(buf), 0);
  sprintf(buf, "\r\n");
  send(s, buf, strlen(buf), 0);
}


x86 assembly (clang, -O0):
<transmit_headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x23b0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x2348(%rbp)
cmp    $0x0,%rax
je     11c7 <transmit_headers+0x77>
mov    -0x2348(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11b4 <transmit_headers+0x64>
lea    0xe5d(%rip),%rax
mov    %rax,-0x2350(%rbp)
jmp    11c2 <transmit_headers+0x72>
lea    0xe55(%rip),%rax
mov    %rax,-0x2350(%rbp)
jmp    11c7 <transmit_headers+0x77>
lea    -0x2340(%rbp),%rdi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x23ac(%rbp)
lea    -0x2340(%rbp),%rax
mov    %rax,-0x23a8(%rbp)
lea    -0x2340(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x23ac(%rbp),%edi
mov    -0x23a8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x2340(%rbp),%rdi
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x239c(%rbp)
lea    -0x2340(%rbp),%rax
mov    %rax,-0x2398(%rbp)
lea    -0x2340(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x239c(%rbp),%edi
mov    -0x2398(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x2340(%rbp),%rdi
mov    -0x2350(%rbp),%rdx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x238c(%rbp)
lea    -0x2340(%rbp),%rax
mov    %rax,-0x2388(%rbp)
lea    -0x2340(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x238c(%rbp),%edi
mov    -0x2388(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x2340(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x237c(%rbp)
lea    -0x2340(%rbp),%rax
mov    %rax,-0x2378(%rbp)
lea    -0x2340(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x237c(%rbp),%edi
mov    -0x2378(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x2340(%rbp),%rdi
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x236c(%rbp)
lea    -0x2340(%rbp),%rax
mov    %rax,-0x2368(%rbp)
lea    -0x2340(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x236c(%rbp),%edi
mov    -0x2368(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x2340(%rbp),%rdi
lea    0xd25(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x235c(%rbp)
lea    -0x2340(%rbp),%rax
mov    %rax,-0x2358(%rbp)
lea    -0x2340(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x235c(%rbp),%edi
mov    -0x2358(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
add    $0x23b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transmit_headers>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2328,%rsp
mov    %edx,%r14d
mov    %edi,%ebp
mov    %rsi,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     119a <transmit_headers+0x4a>
lea    0xe85(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xe78(%rip),%rax
lea    0xe7c(%rip),%r15
cmove  %rax,%r15
jmp    119a <transmit_headers+0x4a>
movups 0xe79(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0xa,0x10(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
movups 0xe60(%rip),%xmm0
movaps %xmm0,(%rsp)
movups 0xe5e(%rip),%xmm0
movups %xmm0,0x9(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    0xe35(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
movups 0xe20(%rip),%xmm0
movaps %xmm0,(%rsp)
movups 0xe25(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
movw   $0xa0d,(%rsp)
movb   $0x0,0x2(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
add    $0x2328,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".jpg\00"
@.str.1 = [11 x i8] c"image/jpeg\00"
@.str.2 = [10 x i8] c"text/html\00"
@.str.3 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.4 = [25 x i8] c"Connection: keep-alive\0D\0A\00"
@.str.5 = [19 x i8] c"Content-Type: %s\0D\0A\00"
@.str.6 = [21 x i8] c"Content-Length: %d\0D\0A\00"
@.str.7 = [32 x i8] c"Server: cs360httpd/1.0 (Unix)\0D\0A\00"
@.str.8 = [3 x i8] c"\0D\0A\00"
define void @transmit_headers(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [9000 x i8]
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%11 = call i8* @strrchr(i8* %10, i8 signext 46)
store i8* %11, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = load i8*, i8** %8
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %19
18: ; preds = %13
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %19
19: ; preds = %18, %17
br label %20
20: ; preds = %19, %3
%21 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%25 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @send(i32 %23, i8* %24, i32 %26, i32 0)
%28 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* %4
%31 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%32 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @send(i32 %30, i8* %31, i32 %33, i32 0)
%35 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%36 = load i8*, i8** %9
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %4
%39 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%40 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = call i32 @send(i32 %38, i8* %39, i32 %41, i32 0)
%43 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%44 = load i32, i32* %6
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %4
%47 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%48 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = call i32 @send(i32 %46, i8* %47, i32 %49, i32 0)
%51 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%53 = load i32, i32* %4
%54 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%55 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @send(i32 %53, i8* %54, i32 %56, i32 0)
%58 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%59 = call i32 (i8*, i8*, ...) @sprintf(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%60 = load i32, i32* %4
%61 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%62 = getelementptr inbounds [9000 x i8], [9000 x i8]* %7, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
%64 = call i32 @send(i32 %60, i8* %61, i32 %63, i32 0)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".jpg\00"
@.str.1 = [11 x i8] c"image/jpeg\00"
@.str.2 = [10 x i8] c"text/html\00"
@.str.3 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.4 = [25 x i8] c"Connection: keep-alive\0D\0A\00"
@.str.5 = [19 x i8] c"Content-Type: %s\0D\0A\00"
@.str.6 = [21 x i8] c"Content-Length: %d\0D\0A\00"
@.str.7 = [32 x i8] c"Server: cs360httpd/1.0 (Unix)\0D\0A\00"
@.str.8 = [3 x i8] c"\0D\0A\00"
define void @transmit_headers(i32 %0, i8* %1, i32 %2) {
%4 = alloca [9000 x i8]
%5 = getelementptr inbounds [9000 x i8], [9000 x i8]* %4, i64 0, i64 0
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
br label %12
12: ; preds = %8, %3
%13 = phi i8* [ undef, %3 ], [ %11, %8 ]
%14 = call i32 @strlen(i8* %5)
%15 = call i32 @send(i32 %0, i8* %5, i32 %14, i32 0)
%16 = call i32 @strlen(i8* %5)
%17 = call i32 @send(i32 %0, i8* %5, i32 %16, i32 0)
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %13)
%19 = call i32 @strlen(i8* %5)
%20 = call i32 @send(i32 %0, i8* %5, i32 %19, i32 0)
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %2)
%22 = call i32 @strlen(i8* %5)
%23 = call i32 @send(i32 %0, i8* %5, i32 %22, i32 0)
%24 = call i32 @strlen(i8* %5)
%25 = call i32 @send(i32 %0, i8* %5, i32 %24, i32 0)
%26 = call i32 @strlen(i8* %5)
%27 = call i32 @send(i32 %0, i8* %5, i32 %26, i32 0)
ret void
}