void http_send(struct http_msg *handle, char *data, int remaining_length) {
  int sent = 0;
  int total_sent = 0;
  int retries_left = 5;
  while (remaining_length > 0) {
    sent = http_send_asm(handle, data + total_sent, remaining_length);
    if (sent == -1) {
      --retries_left;
      if (retries_left)
        continue;
      else {
        debug_board_write_str("ERROR: HTTP LIBRARY : Could not send data.\n");
        __asm__ __volatile__("int3");
      }
    }
    remaining_length -= sent;
    total_sent += sent;
  }
}


x86 assembly (clang, -O0):
<http_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x5,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11bd <http_send+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1030 <http_send_asm@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11a4 <http_send+0x84>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1190 <http_send+0x70>
jmp    1148 <http_send+0x28>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <debug_board_write_str@plt>
int3
jmp    11a4 <http_send+0x84>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <http_send+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
test   %edx,%edx
jle    118f <http_send+0x6f>
mov    %edx,%r13d
mov    %rdi,%r15
mov    $0x5,%r12d
mov    (%rsp),%rbx
xor    %r14d,%r14d
jmp    1170 <http_send+0x50>
xor    %r12d,%r12d
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1040 <debug_board_write_str@plt>
int3
add    %ebp,%r14d
movslq %r14d,%rbx
add    (%rsp),%rbx
sub    %ebp,%r13d
jle    118f <http_send+0x6f>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <http_send_asm@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    115a <http_send+0x3a>
add    $0xffffffff,%r12d
jne    1170 <http_send+0x50>
jmp    1148 <http_send+0x28>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.http_msg = type opaque
@.str = [44 x i8] c"ERROR: HTTP LIBRARY : Could not send data.\0A\00"
define void @http_send(%struct.http_msg* %0, i8* %1, i32 %2) {
%4 = alloca %struct.http_msg*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.http_msg* %0, %struct.http_msg** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 5, i32* %9
br label %10
10: ; preds = %32, %28, %3
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %39
13: ; preds = %10
%14 = load %struct.http_msg*, %struct.http_msg** %4
%15 = load i8*, i8** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i32, i32* %6
%20 = call i32 (%struct.http_msg*, i8*, i32, ...) bitcast (i32 (...)* @http_send_asm to i32 (%struct.http_msg*, i8*, i32, ...)*)(%struct.http_msg* %14, i8* %18, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %32
23: ; preds = %13
%24 = load i32, i32* %9
%25 = add nsw i32 %24, -1
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
br label %10
29: ; preds = %23
%30 = call i32 (i8*, ...) bitcast (i32 (...)* @debug_board_write_str to i32 (i8*, ...)*)(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29
br label %32
32: ; preds = %31, %13
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, %33
store i32 %35, i32* %6
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = add nsw i32 %37, %36
store i32 %38, i32* %8
br label %10
39: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.http_msg = type opaque
@.str = [44 x i8] c"ERROR: HTTP LIBRARY : Could not send data.\0A\00"
define void @http_send(%struct.http_msg* %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %26
5: ; preds = %3, %19
%6 = phi i8* [ %25, %19 ], [ %1, %3 ]
%7 = phi i32 [ %20, %19 ], [ 5, %3 ]
%8 = phi i32 [ %22, %19 ], [ 0, %3 ]
%9 = phi i32 [ %21, %19 ], [ %2, %3 ]
br label %10
10: ; preds = %5, %14
%11 = phi i32 [ %15, %14 ], [ %7, %5 ]
%12 = tail call i32 (%struct.http_msg*, i8*, i32, ...) bitcast (i32 (...)* @http_send_asm to i32 (%struct.http_msg*, i8*, i32, ...)*)(%struct.http_msg* %0, i8* %6, i32 %9)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = add nsw i32 %11, -1
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %10
17: ; preds = %14
%18 = tail call i32 (i8*, ...) bitcast (i32 (...)* @debug_board_write_str to i32 (i8*, ...)*)(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
tail call void asm sideeffect "int3", "~{dirflag},~{fpsr},~{flags}"()
br label %19
19: ; preds = %10, %17
%20 = phi i32 [ 0, %17 ], [ %11, %10 ]
%21 = sub nsw i32 %9, %12
%22 = add nsw i32 %12, %8
%23 = icmp sgt i32 %21, 0
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
br i1 %23, label %5, label %26
26: ; preds = %19, %3
ret void
}