#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int sendMessage(int, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int writeStart(int sock, char *name) {
  int size = strlen("START\n") + strlen("name:") + strlen(name) + strlen("\n") +
             strlen("\n") + 1;
  char *start_str = malloc(sizeof(char) * size);
  if (start_str == NULL) {
    perror("malloc");
    return -1;
  }
  strcpy(start_str, "START\n");
  strcat(start_str, "name:");
  strcat(start_str, name);
  strcat(start_str, "\n");
  strcat(start_str, "\n");
  int sent = sendMessage(sock, start_str);
  free(start_str);
  if (sent == -1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<writeStart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe7a(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x34(%rbp)
lea    0xe72(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
lea    0xe47(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
lea    0xe31(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121c <writeStart+0xac>
lea    0xe02(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129e <writeStart+0x12e>
mov    -0x20(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xda1(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <sendMessage@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0xffffffff,-0x24(%rbp)
jne    1297 <writeStart+0x127>
movl   $0xffffffff,-0x4(%rbp)
jmp    129e <writeStart+0x12e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeStart>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,0x4(%rsp)
lea    0xe77(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
lea    0xe6f(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0xe55(%rip),%r13
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1050 <strlen@plt>
add    %r12d,%ebx
add    %ebp,%ebx
add    %r14d,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1253 <writeStart+0xe3>
mov    %rax,%rbp
lea    0xe1b(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
lea    0xe13(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
lea    0xdf7(%rip),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    0x4(%rsp),%edi
mov    %rbp,%rsi
call   1060 <sendMessage@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebx
sete   %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb3(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
jmp    1244 <writeStart+0xd4>

LLVM IR (-O0):
@.str = [7 x i8] c"START\0A\00"
@.str.1 = [6 x i8] c"name:\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [7 x i8] c"malloc\00"
define i32 @writeStart(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = add nsw i32 %9, %10
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %11, %13
%15 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = add nsw i32 %14, %15
%17 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = add nsw i32 %16, %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = mul i64 1, %21
%23 = trunc i64 %22 to i32
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %2
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %50
29: ; preds = %2
%30 = load i8*, i8** %7
%31 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%32 = load i8*, i8** %7
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%34 = load i8*, i8** %7
%35 = load i8*, i8** %5
%36 = call i32 @strcat(i8* %34, i8* %35)
%37 = load i8*, i8** %7
%38 = call i32 @strcat(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = load i8*, i8** %7
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* %4
%42 = load i8*, i8** %7
%43 = call i32 @sendMessage(i32 %41, i8* %42)
store i32 %43, i32* %8
%44 = load i8*, i8** %7
%45 = call i32 @free(i8* %44)
%46 = load i32, i32* %8
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %49
48: ; preds = %29
store i32 -1, i32* %3
br label %50
49: ; preds = %29
store i32 0, i32* %3
br label %50
50: ; preds = %49, %48, %27
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [7 x i8] c"START\0A\00"
@.str.1 = [6 x i8] c"name:\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [7 x i8] c"malloc\00"
define i32 @writeStart(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = add i32 %3, 1
%9 = add i32 %8, %4
%10 = add i32 %9, %5
%11 = add i32 %10, %6
%12 = add i32 %11, %7
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %27
17: ; preds = %2
%18 = tail call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @strcat(i8* %13, i8* %1)
%21 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @sendMessage(i32 %0, i8* %13)
%24 = tail call i32 @free(i8* %13)
%25 = icmp eq i32 %23, -1
%26 = sext i1 %25 to i32
br label %27
27: ; preds = %17, %15
%28 = phi i32 [ -1, %15 ], [ %26, %17 ]
ret i32 %28
}