#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 int /*<<< orphan*/ res2;
typedef int /*<<< orphan*/ res1;
typedef int /*<<< orphan*/ interface;

/* Variables and functions */
int NI_MAXHOST;
int /*<<< orphan*/ getIP(char *, char *);
int /*<<< orphan*/ getInterface(char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
int strlen(char *);
char *createResponse() {
  char res1[] = "HTTP/1.1 200 OK\r\n"
                "CACHE-CONTROL: max-age=1800\r\n"
                "Date: Thu, 01 Jan 1970 00:24:51 GMT\r\n"
                "EXT:\r\n"
                "LOCATION: http://";
  char res2[] = ":80/RCR.txt\r\n"
                "SERVER: SHP, UPnP/1.0, Samsung UPnP SDK/1.0\r\n"
                "ST: urn:samsung.com:device:RemoteControlReceiver:1\r\n"
                "USN: "
                "uuid:01234567-89ab-cdef-0123-456789abcdef::urn:samsung.com:"
                "device:RemoteControlReceiver:1\r\n"
                "Content-Length: 0\r\n\r\n";
  char interface[32];
  getInterface(interface, sizeof(interface));
  char host[NI_MAXHOST];
  getIP(interface, host);
  char *response = (char *)malloc(
      sizeof(char) * (sizeof(res1) + strlen(host) + sizeof(res2) + 1));
  sprintf(response, "%s%s%s", res1, host, res2);
  return response;
}


x86 assembly (clang, -O0):
<createResponse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
movups 0xee9(%rip),%xmm0
movups %xmm0,-0x15(%rbp)
movaps 0xed3(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xe82(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xe67(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xe4c(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
lea    0xeb1(%rip),%rsi
lea    -0x160(%rbp),%rdi
mov    $0xe4,%edx
call   1050 <memcpy@plt>
lea    -0x180(%rbp),%rdi
mov    $0x20,%esi
call   1040 <getInterface@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x188(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x1a0(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x190(%rbp)
lea    -0x180(%rbp),%rdi
call   1080 <getIP@plt>
mov    -0x1a0(%rbp),%rdi
call   1030 <strlen@plt>
cltq
add    $0x6b,%rax
add    $0xe4,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    -0x1a0(%rbp),%rcx
mov    %rax,-0x198(%rbp)
mov    -0x198(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    -0x160(%rbp),%r8
lea    0xee4(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x198(%rbp),%rax
mov    -0x188(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createResponse>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x180,%rsp
movups 0xee2(%rip),%xmm0
movups %xmm0,-0x35(%rbp)
movaps 0xecc(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xe96(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movaps 0xe60(%rip),%xmm0
movaps %xmm0,-0x80(%rbp)
movaps 0xe45(%rip),%xmm0
movaps %xmm0,-0x90(%rbp)
lea    0xea7(%rip),%rsi
lea    -0x1a0(%rbp),%r14
mov    $0xe4,%edx
mov    %r14,%rdi
call   1050 <memcpy@plt>
lea    -0xb0(%rbp),%r15
mov    %r15,%rdi
mov    $0x20,%esi
call   1040 <getInterface@plt>
mov    %rsp,%r12
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <getIP@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x150(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xf1e(%rip),%rsi
lea    -0x90(%rbp),%rdx
mov    %rax,%rdi
mov    %rbx,%rcx
mov    %r14,%r8
call   1070 <sprintf@plt>
mov    %r12,%rsp
mov    %r15,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.createResponse.res1 = [107 x i8] c"HTTP/1.1 200 OK\0D\0ACACHE-CONTROL: max-age=1800\0D\0ADate: Thu, 01 Jan 1970 00:24:51 GMT\0D\0AEXT:\0D\0ALOCATION: http://\00"
@__const.createResponse.res2 = [228 x i8] c":80/RCR.txt\0D\0ASERVER: SHP, UPnP/1.0, Samsung UPnP SDK/1.0\0D\0AST: urn:samsung.com:device:RemoteControlReceiver:1\0D\0AUSN: uuid:01234567-89ab-cdef-0123-456789abcdef::urn:samsung.com:device:RemoteControlReceiver:1\0D\0AContent-Length: 0\0D\0A\0D\0A\00"
@NI_MAXHOST = global i32 0
@.str = [7 x i8] c"%s%s%s\00"
define i8* @createResponse() {
%1 = alloca [107 x i8]
%2 = alloca [228 x i8]
%3 = alloca [32 x i8]
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = bitcast [107 x i8]* %1 to i8*
%8 = bitcast [228 x i8]* %2 to i8*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%10 = call i32 @getInterface(i8* %9, i32 32)
%11 = load i32, i32* @NI_MAXHOST
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%16 = call i32 @getIP(i8* %15, i8* %14)
%17 = call i32 @strlen(i8* %14)
%18 = sext i32 %17 to i64
%19 = add i64 107, %18
%20 = add i64 %19, 228
%21 = add i64 %20, 1
%22 = mul i64 1, %21
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = getelementptr inbounds [107 x i8], [107 x i8]* %1, i64 0, i64 0
%28 = getelementptr inbounds [228 x i8], [228 x i8]* %2, i64 0, i64 0
%29 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %14, i8* %28)
%30 = load i8*, i8** %6
%31 = load i8*, i8** %4
ret i8* %30
}

LLVM IR (-O2):
@__const.createResponse.res1 = [107 x i8] c"HTTP/1.1 200 OK\0D\0ACACHE-CONTROL: max-age=1800\0D\0ADate: Thu, 01 Jan 1970 00:24:51 GMT\0D\0AEXT:\0D\0ALOCATION: http://\00"
@__const.createResponse.res2 = [228 x i8] c":80/RCR.txt\0D\0ASERVER: SHP, UPnP/1.0, Samsung UPnP SDK/1.0\0D\0AST: urn:samsung.com:device:RemoteControlReceiver:1\0D\0AUSN: uuid:01234567-89ab-cdef-0123-456789abcdef::urn:samsung.com:device:RemoteControlReceiver:1\0D\0AContent-Length: 0\0D\0A\0D\0A\00"
@NI_MAXHOST = global i32 0
@.str = [7 x i8] c"%s%s%s\00"
define i8* @createResponse() {
%1 = alloca [107 x i8]
%2 = alloca [228 x i8]
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [107 x i8], [107 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [228 x i8], [228 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = call i32 @getInterface(i8* %6, i32 32)
%8 = load i32, i32* @NI_MAXHOST
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = call i32 @getIP(i8* %6, i8* %11)
%13 = call i32 @strlen(i8* %11)
%14 = add i32 %13, 336
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = call i32 @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %11, i8* %5)
ret i8* %16
}