#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*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void respond(int len, char *mime, int socketfd) {
  char buffer[128];
  sprintf(buffer,
          "HTTP/1.1 200 OK\r\nServer: nanorestfile\r\nContent-Length: %d\r\n",
          len);
  write(socketfd, buffer, strlen(buffer));
  sprintf(buffer, "Connection: close\r\nContent-Type: text/%s\r\n\r\n", mime);
  write(socketfd, buffer, strlen(buffer));
}


x86 assembly (clang, -O0):
<respond>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xac(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<respond>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%edx
lea    0xeb7(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xecb(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [60 x i8] c"HTTP/1.1 200 OK\0D\0AServer: nanorestfile\0D\0AContent-Length: %d\0D\0A\00"
@.str.1 = [45 x i8] c"Connection: close\0D\0AContent-Type: text/%s\0D\0A\0D\0A\00"
define void @respond(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [128 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* %4
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %6
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @write(i32 %11, i8* %12, i32 %14)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %6
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = call i32 @write(i32 %19, i8* %20, i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [60 x i8] c"HTTP/1.1 200 OK\0D\0AServer: nanorestfile\0D\0AContent-Length: %d\0D\0A\00"
@.str.1 = [45 x i8] c"Connection: close\0D\0AContent-Type: text/%s\0D\0A\0D\0A\00"
define void @respond(i32 %0, i8* %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = call i32 @strlen(i8* %5)
%8 = call i32 @write(i32 %2, i8* %5, i32 %7)
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%10 = call i32 @strlen(i8* %5)
%11 = call i32 @write(i32 %2, i8* %5, i32 %10)
ret void
}