#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 *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int write(int, char *, int);
void sendstring(int sd, char *fname) {
  int n, byteswritten = 0, written;
  char buffer[1024];
  strcpy(buffer, fname);
  n = strlen(buffer);
  while (byteswritten < n) {
    written = write(sd, buffer + byteswritten, (n - byteswritten));
    byteswritten += written;
  }
  printf("String  : %s sent to server \n", buffer);
}


x86 assembly (clang, -O0):
<sendstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b1 <sendstring+0x71>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1178 <sendstring+0x38>
lea    -0x420(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1060 <printf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendstring>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%r14d
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1189 <sendstring+0x49>
mov    %eax,%ebp
xor    %eax,%eax
nopl   0x0(%rax)
movslq %eax,%rbx
lea    (%rsp,%rbx,1),%rsi
mov    %ebp,%edx
sub    %ebx,%edx
mov    %r14d,%edi
call   1040 <write@plt>
add    %ebx,%eax
cmp    %eax,%ebp
jg     1170 <sendstring+0x30>
lea    0xe70(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"String : %s sent to server \0A\00"
define void @sendstring(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %6
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %5
br label %14
14: ; preds = %18, %2
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i32, i32* %3
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = sub nsw i32 %24, %25
%27 = call i32 @write(i32 %19, i8* %23, i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = load i32, i32* %6
%30 = add nsw i32 %29, %28
store i32 %30, i32* %6
br label %14
31: ; preds = %14
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %32)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"String : %s sent to server \0A\00"
define void @sendstring(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %1)
%6 = call i32 @strlen(i8* %4)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %2, %8
%9 = phi i32 [ %14, %8 ], [ 0, %2 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %10
%12 = sub nsw i32 %6, %9
%13 = call i32 @write(i32 %0, i8* %11, i32 %12)
%14 = add nsw i32 %13, %9
%15 = icmp sgt i32 %6, %14
br i1 %15, label %8, label %16
16: ; preds = %8, %2
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %4)
ret void
}