#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 *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
void SendMessage3(int msgsock, char *responsecode, char *version, char *key,
                  char *value, int len, char *body) {
  char buf[(200)];
  strcpy(buf, version);
  strcat(buf, " ");
  strcat(buf, responsecode);
  strcat(buf, " OK\r\n");
  strcat(buf, key);
  strcat(buf, ": ");
  strcat(buf, value);
  strcat(buf, "\r\nContent-Length: ");
  char length[5];
  sprintf(length, "%d", len);
  strcat(buf, length);
  strcat(buf, "\r\n\r\n");
  strcat(buf, body);
  if (write(msgsock, buf, strlen(buf) + 1) < 0) {
    perror("writing on stream socket");
  }
}


x86 assembly (clang, -O0):
<SendMessage3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x100(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x100(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x100(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x100(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x100(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x100(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x100(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x105(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xdf6(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x100(%rbp),%rdi
lea    -0x105(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x100(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x100(%rbp),%rdi
mov    0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x114(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x110(%rbp)
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x114(%rbp),%edi
mov    -0x110(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    12b0 <SendMessage3+0x150>
lea    0xd76(%rip),%rdi
call   1060 <perror@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendMessage3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %r9d,%r12d
mov    %r8,%r13
mov    %rcx,%rbp
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rdx,%rsi
call   1030 <strcpy@plt>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strcat@plt>
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <strcat@plt>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xe25(%rip),%rsi
lea    0xb(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12d,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strcat@plt>
lea    0xe06(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    0x110(%rsp),%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
test   %rax,%rax
js     125c <SendMessage3+0xfc>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbe(%rip),%rdi
call   1060 <perror@plt>
jmp    124a <SendMessage3+0xea>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [6 x i8] c" OK\0D\0A\00"
@.str.2 = [3 x i8] c": \00"
@.str.3 = [19 x i8] c"\0D\0AContent-Length: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.6 = [25 x i8] c"writing on stream socket\00"
define void @SendMessage3(i32 %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5, i8* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca [200 x i8]
%16 = alloca [5 x i8]
store i32 %0, i32* %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i32 %5, i32* %13
store i8* %6, i8** %14
%17 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%18 = load i8*, i8** %10
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%23 = load i8*, i8** %9
%24 = call i32 @strcat(i8* %22, i8* %23)
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%28 = load i8*, i8** %11
%29 = call i32 @strcat(i8* %27, i8* %28)
%30 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%32 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%33 = load i8*, i8** %12
%34 = call i32 @strcat(i8* %32, i8* %33)
%35 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%36 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %16, i64 0, i64 0
%38 = load i32, i32* %13
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%41 = getelementptr inbounds [5 x i8], [5 x i8]* %16, i64 0, i64 0
%42 = call i32 @strcat(i8* %40, i8* %41)
%43 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%45 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%46 = load i8*, i8** %14
%47 = call i32 @strcat(i8* %45, i8* %46)
%48 = load i32, i32* %8
%49 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%50 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%51 = call i64 @strlen(i8* %50)
%52 = add nsw i64 %51, 1
%53 = call i64 @write(i32 %48, i8* %49, i64 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %7
%56 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %57
57: ; preds = %55, %7
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [6 x i8] c" OK\0D\0A\00"
@.str.2 = [3 x i8] c": \00"
@.str.3 = [19 x i8] c"\0D\0AContent-Length: \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.6 = [25 x i8] c"writing on stream socket\00"
define void @SendMessage3(i32 %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5, i8* %6) {
%8 = alloca [200 x i8]
%9 = alloca [5 x i8]
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%11 = call i32 @strcpy(i8* %10, i8* %2)
%12 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @strcat(i8* %10, i8* %1)
%14 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @strcat(i8* %10, i8* %3)
%16 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @strcat(i8* %10, i8* %4)
%18 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%20 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %5)
%21 = call i32 @strcat(i8* %10, i8* %19)
%22 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 @strcat(i8* %10, i8* %6)
%24 = call i64 @strlen(i8* %10)
%25 = add nsw i64 %24, 1
%26 = call i64 @write(i32 %0, i8* %10, i64 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %7
%29 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %30
30: ; preds = %28, %7
ret void
}