#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 scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *safe_malloc(int);
int /*<<< orphan*/ server_error(int, char *);
int /*<<< orphan*/ sprintf(char *, char *, long long);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int client_200(int sock, off_t file_len, const char *cont_type) {
  char *buf = safe_malloc(256);
  char *flen = safe_malloc(256);
  sprintf(flen, "%lld", (long long int)file_len);
  strcpy(buf, "HTTP/1.1 200 OK\r\n");
  strcat(buf, "Content-Type: ");
  strcat(buf, cont_type);
  strcat(buf, "\r\nContent-Length: ");
  strcat(buf, flen);
  strcat(buf, "\r\nConnection: close");
  strcat(buf, "\r\n\r\n");
  if ((write(sock, buf, strlen(buf)) < 0)) {
    free(buf);
    free(flen);
    server_error(sock, "writing 200 to client");
    return 1;
  }
  free(buf);
  free(flen);
  return 0;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x100,%edi
call   1050 <safe_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x100,%edi
call   1050 <safe_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe42(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1060 <write@plt>
cmp    $0x0,%rax
jge    1289 <client_200+0x109>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
lea    0xdda(%rip),%rsi
call   1080 <server_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a2 <client_200+0x122>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%r14d
mov    $0x100,%edi
call   1050 <safe_malloc@plt>
mov    %rax,%rbx
mov    $0x100,%edi
call   1050 <safe_malloc@plt>
mov    %rax,%r12
lea    0xe4e(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
call   10a0 <sprintf@plt>
lea    0xe41(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe37(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
test   %rbp,%rbp
jns    1261 <client_200+0xe1>
lea    0xdfe(%rip),%rsi
mov    %r14d,%edi
call   1080 <server_error@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.2 = [15 x i8] c"Content-Type: \00"
@.str.3 = [19 x i8] c"\0D\0AContent-Length: \00"
@.str.4 = [20 x i8] c"\0D\0AConnection: close\00"
@.str.5 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.6 = [22 x i8] c"writing 200 to client\00"
define i32 @client_200(i32 %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%10 = call i8* @safe_malloc(i32 256)
store i8* %10, i8** %8
%11 = call i8* @safe_malloc(i32 256)
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = load i64, i64* %6
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %13)
%15 = load i8*, i8** %8
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %8
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %8
%20 = load i8*, i8** %7
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %8
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%24 = load i8*, i8** %8
%25 = load i8*, i8** %9
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %8
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%29 = load i8*, i8** %8
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* %5
%32 = load i8*, i8** %8
%33 = load i8*, i8** %8
%34 = call i32 @strlen(i8* %33)
%35 = call i64 @write(i32 %31, i8* %32, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %3
%38 = load i8*, i8** %8
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %9
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* %5
%43 = call i32 @server_error(i32 %42, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %4
br label %49
44: ; preds = %3
%45 = load i8*, i8** %8
%46 = call i32 @free(i8* %45)
%47 = load i8*, i8** %9
%48 = call i32 @free(i8* %47)
store i32 0, i32* %4
br label %49
49: ; preds = %44, %37
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.2 = [15 x i8] c"Content-Type: \00"
@.str.3 = [19 x i8] c"\0D\0AContent-Length: \00"
@.str.4 = [20 x i8] c"\0D\0AConnection: close\00"
@.str.5 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.6 = [22 x i8] c"writing 200 to client\00"
define i32 @client_200(i32 %0, i64 %1, i8* %2) {
%4 = tail call i8* @safe_malloc(i32 256)
%5 = tail call i8* @safe_malloc(i32 256)
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %1)
%7 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @strcat(i8* %4, i8* %2)
%10 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @strcat(i8* %4, i8* %5)
%12 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 @strlen(i8* %4)
%15 = tail call i64 @write(i32 %0, i8* %4, i32 %14)
%16 = icmp slt i64 %15, 0
%17 = tail call i32 @free(i8* %4)
%18 = tail call i32 @free(i8* %5)
br i1 %16, label %19, label %21
19: ; preds = %3
%20 = tail call i32 @server_error(i32 %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
br label %21
21: ; preds = %3, %19
%22 = phi i32 [ 1, %19 ], [ 0, %3 ]
ret i32 %22
}