#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 */
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int send_to_socket(int connfd, int data[], int num) {
  char str[1024];
  int i;
  memset(str, 0, sizeof(str));
  for (i = 0; i < num; i++) {
    sprintf(str, "%d\n", data[i]);
    if (-1 == send(connfd, str, strlen(str), 0))
      printf("send data failed\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<send_to_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121f <send_to_socket+0xcf>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x424(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe53(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x434(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x434(%rbp),%edi
mov    -0x430(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1206 <send_to_socket+0xb6>
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
jmp    120b <send_to_socket+0xbb>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    1182 <send_to_socket+0x32>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_to_socket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %edi,%r13d
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
test   %ebx,%ebx
jle    11d2 <send_to_socket+0x82>
mov    %ebx,%ebp
xor    %r12d,%r12d
lea    0xe78(%rip),%r14
mov    %rsp,%rbx
jmp    1199 <send_to_socket+0x49>
nopl   (%rax)
add    $0x1,%r12
cmp    %r12,%rbp
je     11d2 <send_to_socket+0x82>
mov    (%r15,%r12,4),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0xffffffff,%eax
jne    1190 <send_to_socket+0x40>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
jmp    1190 <send_to_socket+0x40>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@str = [17 x i8] c"send data failed\00"
define i32 @send_to_socket(i32 %0, i32* nocapture %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 1024)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %23
8: ; preds = %3
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %20
%11 = phi i64 [ 0, %8 ], [ %21, %20 ]
%12 = getelementptr inbounds i32, i32* %1, i64 %11
%13 = load i32, i32* %12
%14 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @strlen(i8* %5)
%16 = call i32 @send(i32 %0, i8* %5, i32 %15, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %10, %18
%21 = add nuw nsw i64 %11, 1
%22 = icmp eq i64 %21, %9
br i1 %22, label %23, label %10
23: ; preds = %20, %3
ret i32 0
}