#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 */
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int send_data(int, char *, int, struct sockaddr *, int /*<<< orphan*/);
int snprintf(char *, int, char *, ...);
int send_response(int sockfd, struct sockaddr *addr, socklen_t socklen,
                  const char *status, const char *message) {
  char line[1024];
  int l;
  l = snprintf(line, sizeof(line), "response: %s", status);
  if (message != NULL)
    l += snprintf(line + l, sizeof(line) - l, " %s\n", message);
  else
    l += snprintf(line + l, sizeof(line) - l, "\n");
  return send_data(sockfd, line, l, addr, socklen);
}


x86 assembly (clang, -O0):
<send_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x400,%esi
lea    0xeac(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x434(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b1 <send_response+0x91>
lea    -0x430(%rbp),%rdi
movslq -0x434(%rbp),%rax
add    %rax,%rdi
movslq -0x434(%rbp),%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
lea    0xe74(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
add    -0x434(%rbp),%eax
mov    %eax,-0x434(%rbp)
jmp    11ed <send_response+0xcd>
lea    -0x430(%rbp),%rdi
movslq -0x434(%rbp),%rax
add    %rax,%rdi
movslq -0x434(%rbp),%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe36(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
add    -0x434(%rbp),%eax
mov    %eax,-0x434(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x434(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
call   1040 <send_data@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_response>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %r8,%r13
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%r12d
lea    0xebc(%rip),%rdx
mov    %rsp,%rdi
mov    $0x400,%ebp
mov    $0x400,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %eax,%ebx
sub    %eax,%ebp
cltq
lea    (%rsp,%rax,1),%rdi
test   %r13,%r13
je     117c <send_response+0x5c>
lea    0xe9f(%rip),%rdx
mov    %ebp,%esi
mov    %r13,%rcx
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    118c <send_response+0x6c>
lea    0xe8d(%rip),%rdx
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
add    %ebx,%eax
mov    %rsp,%rsi
mov    %r12d,%edi
mov    %eax,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1040 <send_data@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"response: %s\00"
@.str.1 = [5 x i8] c" %s\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @send_response(i32 %0, %struct.sockaddr* %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca %struct.sockaddr*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [1024 x i8]
%12 = alloca i32
store i32 %0, i32* %6
store %struct.sockaddr* %1, %struct.sockaddr** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%14 = load i8*, i8** %9
%15 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %13, i32 1024, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 %15, i32* %12
%16 = load i8*, i8** %10
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %31
18: ; preds = %5
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%20 = load i32, i32* %12
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i32, i32* %12
%24 = sext i32 %23 to i64
%25 = sub i64 1024, %24
%26 = trunc i64 %25 to i32
%27 = load i8*, i8** %10
%28 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %22, i32 %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %12
%30 = add nsw i32 %29, %28
store i32 %30, i32* %12
br label %43
31: ; preds = %5
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i32, i32* %12
%37 = sext i32 %36 to i64
%38 = sub i64 1024, %37
%39 = trunc i64 %38 to i32
%40 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %35, i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* %12
%42 = add nsw i32 %41, %40
store i32 %42, i32* %12
br label %43
43: ; preds = %31, %18
%44 = load i32, i32* %6
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%46 = load i32, i32* %12
%47 = load %struct.sockaddr*, %struct.sockaddr** %7
%48 = load i32, i32* %8
%49 = call i32 @send_data(i32 %44, i8* %45, i32 %46, %struct.sockaddr* %47, i32 %48)
ret i32 %49
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"response: %s\00"
@.str.1 = [5 x i8] c" %s\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @send_response(i32 %0, %struct.sockaddr* %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%8 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %3)
%9 = icmp eq i8* %4, null
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %10
%12 = sub i32 1024, %8
br i1 %9, label %15, label %13
13: ; preds = %5
%14 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %17
15: ; preds = %5
%16 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
%18 = phi i32 [ %14, %13 ], [ %16, %15 ]
%19 = add nsw i32 %18, %8
%20 = call i32 @send_data(i32 %0, i8* %7, i32 %19, %struct.sockaddr* %1, i32 %2)
ret i32 %20
}