#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*/ perror(char *);
int send(int, char *, int, int /*<<< orphan*/);
void send_msg(int sock, char *buf) {
  int sent = 0;
  char *p = buf;
  while (sent < 512) {
    int ret_val = send(sock, p, 512, 0);
    if (ret_val == -1) {
      perror("ERROR: could not send. Trying again...");
      continue;
    }
    sent += ret_val;
  }
}


x86 assembly (clang, -O0):
<send_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x200,-0x14(%rbp)
jge    118a <send_msg+0x6a>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    117c <send_msg+0x5c>
lea    0xe8e(%rip),%rdi
call   1040 <perror@plt>
jmp    113e <send_msg+0x1e>
mov    -0x24(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    113e <send_msg+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_msg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0xecb(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
cmp    $0xffffffff,%eax
je     1162 <send_msg+0x42>
add    %eax,%ebx
cmp    $0x200,%ebx
jl     1140 <send_msg+0x20>
jmp    1172 <send_msg+0x52>
mov    %r14,%rdi
call   1040 <perror@plt>
cmp    $0x200,%ebx
jl     1140 <send_msg+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"ERROR: could not send. Trying again...\00"
define void @send_msg(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i8*, i8** %4
store i8* %8, i8** %6
br label %9
9: ; preds = %20, %18, %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 512
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i32, i32* %3
%14 = load i8*, i8** %6
%15 = call i32 @send(i32 %13, i8* %14, i32 512, i32 0)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %9
20: ; preds = %12
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = add nsw i32 %22, %21
store i32 %23, i32* %5
br label %9
24: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"ERROR: could not send. Trying again...\00"
define void @send_msg(i32 %0, i8* %1) {
br label %3
3: ; preds = %2, %11
%4 = phi i32 [ 0, %2 ], [ %12, %11 ]
%5 = tail call i32 @send(i32 %0, i8* %1, i32 512, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %11
9: ; preds = %3
%10 = add nsw i32 %5, %4
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %4, %7 ], [ %10, %9 ]
%13 = icmp slt i32 %12, 512
br i1 %13, label %3, label %14
14: ; preds = %11
ret void
}