#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 Send(int, char *, int, int /*<<< orphan*/);
char *getArg(char **);
int /*<<< orphan*/ snprintf(char *, int, char *, size_t, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int sendRequest(int sd, char req[], char argv[], int n) {
  int status = -2;
  char *arg;
  size_t size = 1;
  char buf[4096] = {0};
  char miniBuf[4096] = {0};
  snprintf(buf, 4096, "%d:%s", strlen(req), req);
  while (n-- > 0 && size > 0) {
    arg = getArg(&argv);
    size = strlen(arg);
    snprintf(miniBuf, 4096, "%d:%s", size, arg);
    strcat(buf, miniBuf);
  }
  if (size > 0) {
    status = Send(sd, buf, strlen(buf), 0);
  }
  return status;
}


x86 assembly (clang, -O0):
<sendRequest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0xfffffffe,-0x20(%rbp)
movq   $0x1,-0x30(%rbp)
lea    -0x1030(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    -0x2030(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x2038(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2038(%rbp),%rdi
movslq %eax,%rcx
mov    -0x10(%rbp),%r8
mov    $0x1000,%esi
lea    0xe21(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x1c(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2039(%rbp)
jle    120e <sendRequest+0xae>
cmpq   $0x0,-0x30(%rbp)
seta   %al
mov    %al,-0x2039(%rbp)
mov    -0x2039(%rbp),%al
test   $0x1,%al
jne    1221 <sendRequest+0xc1>
jmp    1275 <sendRequest+0x115>
lea    -0x18(%rbp),%rdi
call   1080 <getArg@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x30(%rbp)
lea    -0x2030(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    $0x1000,%esi
lea    0xda8(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x2030(%rbp),%rsi
call   1070 <strcat@plt>
jmp    11e4 <sendRequest+0x84>
cmpq   $0x0,-0x30(%rbp)
jbe    12bc <sendRequest+0x15c>
mov    -0x4(%rbp),%eax
mov    %eax,-0x204c(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x2048(%rbp)
lea    -0x1030(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x204c(%rbp),%edi
mov    -0x2048(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <Send@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendRequest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %ecx,%ebp
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rdx,0x8(%rsp)
lea    0x10(%rsp),%r14
mov    $0x1000,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x1010(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
lea    0xe48(%rip),%rdx
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %rbx,%r8
call   1040 <snprintf@plt>
test   %ebp,%ebp
jle    1240 <sendRequest+0xe0>
mov    %r15d,0x4(%rsp)
lea    0xe28(%rip),%r12
lea    0x1010(%rsp),%rbx
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x8(%rsp),%rdi
call   1080 <getArg@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
movslq %eax,%rcx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
mov    %r15,%r8
call   1040 <snprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
cmp    $0x2,%ebp
jb     1236 <sendRequest+0xd6>
add    $0xffffffff,%ebp
test   %r14d,%r14d
jne    11f0 <sendRequest+0x90>
test   %r14d,%r14d
mov    0x4(%rsp),%r15d
je     125e <sendRequest+0xfe>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <Send@plt>
jmp    1263 <sendRequest+0x103>
mov    $0xfffffffe,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d:%s\00"
define i32 @sendRequest(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca [4096 x i8]
%13 = alloca [4096 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 -2, i32* %9
store i64 1, i64* %11
%14 = bitcast [4096 x i8]* %12 to i8*
%15 = bitcast [4096 x i8]* %13 to i8*
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = load i8*, i8** %6
%21 = call i32 @snprintf(i8* %16, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %19, i8* %20)
br label %22
22: ; preds = %31, %4
%23 = load i32, i32* %8
%24 = add nsw i32 %23, -1
store i32 %24, i32* %8
%25 = icmp sgt i32 %23, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i64, i64* %11
%28 = icmp ugt i64 %27, 0
br label %29
29: ; preds = %26, %22
%30 = phi i1 [ false, %22 ], [ %28, %26 ]
br i1 %30, label %31, label %43
31: ; preds = %29
%32 = call i8* @getArg(i8** %7)
store i8* %32, i8** %10
%33 = load i8*, i8** %10
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
store i64 %35, i64* %11
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%37 = load i64, i64* %11
%38 = load i8*, i8** %10
%39 = call i32 @snprintf(i8* %36, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %37, i8* %38)
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%42 = call i32 @strcat(i8* %40, i8* %41)
br label %22
43: ; preds = %29
%44 = load i64, i64* %11
%45 = icmp ugt i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %43
%47 = load i32, i32* %5
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @Send(i32 %47, i8* %48, i32 %50, i32 0)
store i32 %51, i32* %9
br label %52
52: ; preds = %46, %43
%53 = load i32, i32* %9
ret i32 %53
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d:%s\00"
define i32 @sendRequest(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca [4096 x i8]
store i8* %2, i8** %5
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%10 = tail call i32 @strlen(i8* %1)
%11 = sext i32 %10 to i64
%12 = call i32 @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %11, i8* %1)
%13 = icmp sgt i32 %3, 0
br i1 %13, label %14, label %26
14: ; preds = %4, %14
%15 = phi i32 [ %16, %14 ], [ %3, %4 ]
%16 = add nsw i32 %15, -1
%17 = call i8* @getArg(i8** %5)
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = call i32 @snprintf(i8* %9, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %19, i8* %17)
%21 = call i32 @strcat(i8* %8, i8* %9)
%22 = icmp ugt i32 %15, 1
%23 = icmp ne i32 %18, 0
%24 = and i1 %22, %23
br i1 %24, label %14, label %25
25: ; preds = %14
br i1 %23, label %26, label %29
26: ; preds = %4, %25
%27 = call i32 @strlen(i8* %8)
%28 = call i32 @Send(i32 %0, i8* %8, i32 %27, i32 0)
br label %29
29: ; preds = %26, %25
%30 = phi i32 [ %28, %26 ], [ -2, %25 ]
ret i32 %30
}