#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 *, char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
void respond(int sock, char *message, bool final) {
  char *tail;
  if (final) {
    tail = "\r\n\r\n";
  } else {
    tail = "\r\n";
  }
  char buffer[strlen(message) + strlen(tail) + 1];
  sprintf(buffer, "%s%s", message, tail);
  write(sock, buffer, strlen(buffer) + 1);
}


x86 assembly (clang, -O0):
<respond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     115c <respond+0x2c>
lea    0xead(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1167 <respond+0x37>
lea    0xe9f(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rcx
mov    %rax,%rdx
lea    0x1(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x28(%rbp)
lea    0x10(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe4c(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<respond>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%r14d
xor    %ebx,%ebx
test   %edx,%edx
setne  %bl
lea    0xeb3(%rip),%rax
lea    0xeaa(%rip),%r12
cmove  %rax,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbx,2),%rax
add    $0x12,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [5 x i8] c"%s%s\00"
define void @respond(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
br label %14
13: ; preds = %3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %14
14: ; preds = %13, %12
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
%17 = load i8*, i8** %7
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %16, %18
%20 = add nsw i64 %19, 1
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %8
%22 = alloca i8, i64 %20
store i64 %20, i64* %9
%23 = load i8*, i8** %5
%24 = load i8*, i8** %7
%25 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %24)
%26 = load i32, i32* %4
%27 = call i64 @strlen(i8* %22)
%28 = add nsw i64 %27, 1
%29 = call i32 @write(i32 %26, i8* %22, i64 %28)
%30 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [5 x i8] c"%s%s\00"
define void @respond(i32 %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
%5 = select i1 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = select i1 %4, i64 3, i64 5
%8 = add i64 %7, %6
%9 = alloca i8, i64 %8
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %5)
%11 = call i64 @strlen(i8* %9)
%12 = add nsw i64 %11, 1
%13 = call i32 @write(i32 %0, i8* %9, i64 %12)
ret void
}