#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*/ perror(char *);
scalar_t__ send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *);
scalar_t__ strlen(char *);
void build_success_response(int connection) {
  char buf[255];
  sprintf(buf, "HTTP/1.1 200 Success\r\nConnection: "
               "Close\r\nContent-Type:text/html\r\n\r\n<html><head><title>Test "
               "Page</title></head><body>Nothing here</body></html>\r\n");
  if (send(connection, buf, strlen(buf), 0) < strlen(buf)) {
    perror("Trying to respond");
  }
}


x86 assembly (clang, -O0):
<build_success_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x124(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x124(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x118(%rbp),%rax
cmp    %rcx,%rax
jge    11cd <build_success_response+0x8d>
lea    0xec9(%rip),%rdi
call   1050 <perror@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_success_response>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebp
lea    0xeae(%rip),%rsi
mov    %rsp,%rbx
mov    $0x91,%edx
mov    %rbx,%rdi
call   1050 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbp
jl     1193 <build_success_response+0x53>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xef7(%rip),%rdi
call   1060 <perror@plt>
jmp    1189 <build_success_response+0x49>

LLVM IR (-O0):
@.str = [145 x i8] c"HTTP/1.1 200 Success\0D\0AConnection: Close\0D\0AContent-Type:text/html\0D\0A\0D\0A<html><head><title>Test Page</title></head><body>Nothing here</body></html>\0D\0A\00"
@.str.1 = [18 x i8] c"Trying to respond\00"
define void @build_success_response(i32 %0) {
%2 = alloca i32
%3 = alloca [255 x i8]
store i32 %0, i32* %2
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* %2
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%9 = call i64 @strlen(i8* %8)
%10 = call i64 @send(i32 %6, i8* %7, i64 %9, i32 0)
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%12 = call i64 @strlen(i8* %11)
%13 = icmp slt i64 %10, %12
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
ret void
}

LLVM IR (-O2):
@.str = [145 x i8] c"HTTP/1.1 200 Success\0D\0AConnection: Close\0D\0AContent-Type:text/html\0D\0A\0D\0A<html><head><title>Test Page</title></head><body>Nothing here</body></html>\0D\0A\00"
@.str.1 = [18 x i8] c"Trying to respond\00"
define void @build_success_response(i32 %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = call i64 @strlen(i8* %3)
%5 = call i64 @send(i32 %0, i8* %3, i64 %4, i32 0)
%6 = call i64 @strlen(i8* %3)
%7 = icmp slt i64 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
ret void
}