#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *__get_http_response(char *json_res) {
  char *res = malloc(1024);
  char *json_len = malloc(20);
  sprintf(json_len, "%zu", strlen(json_res));
  strcpy(res,
         "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Type: "
         "application/json\r\nServer: ukahoot-token-server\r\nKeep-Alive: "
         "timeout=15,max=100\r\nContent-Length: ");
  strcat(res, json_len);
  free(json_len);
  strcat(res, "\r\n\r\n");
  strcat(res, json_res);
  free(json_res);
  return res;
}


x86 assembly (clang, -O0):
<__get_http_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe5a(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
lea    0xec8(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__get_http_response>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0xe6f(%rip),%rsi
mov    %r15,%rdi
mov    %eax,%edx
call   1080 <sprintf@plt>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xee0(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%zu\00"
@.str.1 = [160 x i8] c"HTTP/1.1 200 OK\0D\0AAccess-Control-Allow-Origin: *\0D\0AContent-Type: application/json\0D\0AServer: ukahoot-token-server\0D\0AKeep-Alive: timeout=15,max=100\0D\0AContent-Length: \00"
@.str.2 = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @__get_http_response(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i8* @malloc(i32 1024)
store i8* %5, i8** %3
%6 = call i8* @malloc(i32 20)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.1, i64 0, i64 0))
%13 = load i8*, i8** %3
%14 = load i8*, i8** %4
%15 = call i32 @strcat(i8* %13, i8* %14)
%16 = load i8*, i8** %4
%17 = call i32 @free(i8* %16)
%18 = load i8*, i8** %3
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = load i8*, i8** %3
%21 = load i8*, i8** %2
%22 = call i32 @strcat(i8* %20, i8* %21)
%23 = load i8*, i8** %2
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@.str = [4 x i8] c"%zu\00"
@.str.1 = [160 x i8] c"HTTP/1.1 200 OK\0D\0AAccess-Control-Allow-Origin: *\0D\0AContent-Type: application/json\0D\0AServer: ukahoot-token-server\0D\0AKeep-Alive: timeout=15,max=100\0D\0AContent-Length: \00"
@.str.2 = [5 x i8] c"\0D\0A\0D\0A\00"
define i8* @__get_http_response(i8* %0) {
%2 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%3 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @strcat(i8* %2, i8* %3)
%8 = tail call i32 @free(i8* %3)
%9 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @strcat(i8* %2, i8* %0)
%11 = tail call i32 @free(i8* %0)
ret i8* %2
}