#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ failure(char *, int);
int open(char *, int /*<<< orphan*/);
long read(int, char *, int);
int /*<<< orphan*/ respond(long, char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ write(int, char *, long);
void getf(char *uri, int socketfd) {
  int file_fd;
  long len;
  char buffer[50000 + 1], *mime;
  if ((file_fd = open(uri, O_RDONLY)) == -1) {
    failure("404 Not found", socketfd);
    return;
  }
  if ((mime = strchr(uri, '.')))
    mime++;
  else
    mime = "text";
  len = read(file_fd, buffer, 50000);
  respond(len, mime, socketfd);
  write(socketfd, buffer, len);
  close(file_fd);
}


x86 assembly (clang, -O0):
<getf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc380,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    11b4 <getf+0x44>
mov    -0xc(%rbp),%esi
lea    0xe56(%rip),%rdi
call   1070 <failure@plt>
jmp    123e <getf+0xce>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0xc378(%rbp)
cmp    $0x0,%rax
je     11ea <getf+0x7a>
mov    -0xc378(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc378(%rbp)
jmp    11f8 <getf+0x88>
lea    0xe1d(%rip),%rax
mov    %rax,-0xc378(%rbp)
mov    -0x10(%rbp),%edi
lea    -0xc370(%rbp),%rsi
mov    $0xc350,%edx
call   1080 <read@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc378(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <respond@plt>
mov    -0xc(%rbp),%edi
lea    -0xc370(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <write@plt>
mov    -0x10(%rbp),%edi
call   1060 <close@plt>
add    $0xc380,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc360,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1203 <getf+0x93>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
lea    0xe58(%rip),%rbx
cmovne %rcx,%rbx
mov    %rsp,%r15
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0xc350,%edx
call   1080 <read@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <respond@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <write@plt>
mov    %r12d,%edi
add    $0xc360,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <close@plt>
lea    0xdf6(%rip),%rdi
mov    %r14d,%esi
add    $0xc360,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <failure@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [14 x i8] c"404 Not found\00"
@.str.1 = [5 x i8] c"text\00"
define void @getf(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca [50001 x i8]
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i8*, i8** %3
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* %4
%15 = call i32 @failure(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %38
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i8* @strchr(i8* %17, i8 signext 46)
store i8* %18, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %8
br label %24
23: ; preds = %16
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %24
24: ; preds = %23, %20
%25 = load i32, i32* %5
%26 = getelementptr inbounds [50001 x i8], [50001 x i8]* %7, i64 0, i64 0
%27 = call i64 @read(i32 %25, i8* %26, i32 50000)
store i64 %27, i64* %6
%28 = load i64, i64* %6
%29 = load i8*, i8** %8
%30 = load i32, i32* %4
%31 = call i32 @respond(i64 %28, i8* %29, i32 %30)
%32 = load i32, i32* %4
%33 = getelementptr inbounds [50001 x i8], [50001 x i8]* %7, i64 0, i64 0
%34 = load i64, i64* %6
%35 = call i32 @write(i32 %32, i8* %33, i64 %34)
%36 = load i32, i32* %5
%37 = call i32 @close(i32 %36)
br label %38
38: ; preds = %24, %13
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [14 x i8] c"404 Not found\00"
@.str.1 = [5 x i8] c"text\00"
define void @getf(i8* %0, i32 %1) {
%3 = alloca [50001 x i8]
%4 = getelementptr inbounds [50001 x i8], [50001 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @failure(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %19
10: ; preds = %2
%11 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%12 = icmp eq i8* %11, null
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = select i1 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %13
%15 = call i64 @read(i32 %6, i8* %4, i32 50000)
%16 = tail call i32 @respond(i64 %15, i8* %14, i32 %1)
%17 = call i32 @write(i32 %1, i8* %4, i64 %15)
%18 = tail call i32 @close(i32 %6)
br label %19
19: ; preds = %10, %8
ret void
}