#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*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char const *, int);
int strlen(char const *);
int write(int, char *, int);
void sendHello(int fd, const char *msg) {
  char reply[1024];
  int len = strlen(msg);
  sprintf(reply, msg, len);
  reply[len] = '\0';
  printf("reply to send:\n%s\n", reply);
  int sendlen = write(fd, reply, len);
  if (sendlen != len) {
    printf("send length not match\n");
    printf("expected send length:%d, actual send length:%d\n", len,
           (int)sendlen);
  } else {
    printf("send succeed client\n\n");
  }
}


x86 assembly (clang, -O0):
<sendHello>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1060 <sprintf@plt>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%eax
cmp    -0x414(%rbp),%eax
je     11f5 <sendHello+0xb5>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x414(%rbp),%esi
mov    -0x418(%rbp),%edx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1203 <sendHello+0xc3>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendHello>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1070 <sprintf@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
lea    0xe75(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
cmp    %ebx,%eax
jne    11b4 <sendHello+0x64>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
jmp    11d4 <sendHello+0x84>
mov    %eax,%ebp
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4a(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"reply to send:\0A%s\0A\00"
@.str.1 = [23 x i8] c"send length not match\0A\00"
@.str.2 = [48 x i8] c"expected send length:%d, actual send length:%d\0A\00"
@.str.3 = [22 x i8] c"send succeed client\0A\0A\00"
define void @sendHello(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = load i32, i32* %6
%13 = call i32 @sprintf(i8* %10, i8* %11, i32 %12)
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %15
store i8 0, i8* %16
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %3
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %6
%22 = call i32 @write(i32 %19, i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29)
br label %33
31: ; preds = %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"reply to send:\0A%s\0A\00"
@.str.2 = [48 x i8] c"expected send length:%d, actual send length:%d\0A\00"
@str = [21 x i8] c"send succeed client\0A\00"
@str.4 = [22 x i8] c"send length not match\00"
define void @sendHello(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %1)
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) %1, i32 %5)
%7 = sext i32 %5 to i64
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %7
store i8 0, i8* %8
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %4)
%10 = call i32 @write(i32 %0, i8* %4, i32 %5)
%11 = icmp eq i32 %10, %5
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %10)
br label %17
15: ; preds = %2
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
ret void
}