#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*/ g_sleep(int);
scalar_t__ g_tcp_last_error_would_block(int);
int g_tcp_send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scp_lock_fork_critical_section_end(int);
int scp_lock_fork_critical_section_start();
int scp_tcp_force_send(int sck, char *data, int len) {
  int sent;
  int block;
  ;
  block = scp_lock_fork_critical_section_start();
  while (len > 0) {
    sent = g_tcp_send(sck, data, len, 0);
    if (sent == -1) {
      if (g_tcp_last_error_would_block(sck)) {
        g_sleep(1);
      } else {
        scp_lock_fork_critical_section_end(block);
        return 1;
      }
    } else if (sent == 0) {
      scp_lock_fork_critical_section_end(block);
      return 1;
    } else {
      data += sent;
      len -= sent;
    }
  }
  scp_lock_fork_critical_section_end(block);
  return 0;
}


x86 assembly (clang, -O0):
<scp_tcp_force_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1040 <scp_lock_fork_critical_section_start@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1212 <scp_tcp_force_send+0xc2>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1070 <g_tcp_send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11ce <scp_tcp_force_send+0x7e>
mov    -0x8(%rbp),%edi
call   1050 <g_tcp_last_error_would_block@plt>
cmp    $0x0,%rax
je     11b5 <scp_tcp_force_send+0x65>
mov    $0x1,%edi
call   1030 <g_sleep@plt>
jmp    11c9 <scp_tcp_force_send+0x79>
mov    -0x1c(%rbp),%edi
call   1060 <scp_lock_fork_critical_section_end@plt>
movl   $0x1,-0x4(%rbp)
jmp    1221 <scp_tcp_force_send+0xd1>
jmp    120d <scp_tcp_force_send+0xbd>
cmpl   $0x0,-0x18(%rbp)
jne    11ec <scp_tcp_force_send+0x9c>
mov    -0x1c(%rbp),%edi
call   1060 <scp_lock_fork_critical_section_end@plt>
movl   $0x1,-0x4(%rbp)
jmp    1221 <scp_tcp_force_send+0xd1>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    120d <scp_tcp_force_send+0xbd>
jmp    116c <scp_tcp_force_send+0x1c>
mov    -0x1c(%rbp),%edi
call   1060 <scp_lock_fork_critical_section_end@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scp_tcp_force_send>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r12d
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <scp_lock_fork_critical_section_start@plt>
mov    %eax,%r14d
test   %ebp,%ebp
jle    11c2 <scp_tcp_force_send+0x72>
mov    $0x1,%r15d
jmp    1190 <scp_tcp_force_send+0x40>
nopl   0x0(%rax)
test   %eax,%eax
je     11c2 <scp_tcp_force_send+0x72>
movslq %eax,%rcx
add    %rcx,%rbx
sub    %eax,%ebp
test   %ebp,%ebp
jle    11bf <scp_tcp_force_send+0x6f>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1070 <g_tcp_send@plt>
cmp    $0xffffffff,%eax
jne    1180 <scp_tcp_force_send+0x30>
mov    %r12d,%edi
call   1050 <g_tcp_last_error_would_block@plt>
test   %rax,%rax
je     11c2 <scp_tcp_force_send+0x72>
mov    $0x1,%edi
call   1030 <g_sleep@plt>
test   %ebp,%ebp
jg     1190 <scp_tcp_force_send+0x40>
xor    %r15d,%r15d
mov    %r14d,%edi
call   1060 <scp_lock_fork_critical_section_end@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @scp_tcp_force_send(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = call i32 (...) @scp_lock_fork_critical_section_start()
store i32 %10, i32* %9
br label %11
11: ; preds = %46, %3
%12 = load i32, i32* %7
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %47
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = call i32 @g_tcp_send(i32 %15, i8* %16, i32 %17, i32 0)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %31
21: ; preds = %14
%22 = load i32, i32* %5
%23 = call i64 @g_tcp_last_error_would_block(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @g_sleep(i32 1)
br label %30
27: ; preds = %21
%28 = load i32, i32* %9
%29 = call i32 @scp_lock_fork_critical_section_end(i32 %28)
store i32 1, i32* %4
br label %50
30: ; preds = %25
br label %46
31: ; preds = %14
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %9
%36 = call i32 @scp_lock_fork_critical_section_end(i32 %35)
store i32 1, i32* %4
br label %50
37: ; preds = %31
%38 = load i32, i32* %8
%39 = load i8*, i8** %6
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8* %41, i8** %6
%42 = load i32, i32* %8
%43 = load i32, i32* %7
%44 = sub nsw i32 %43, %42
store i32 %44, i32* %7
br label %45
45: ; preds = %37
br label %46
46: ; preds = %45, %30
br label %11
47: ; preds = %11
%48 = load i32, i32* %9
%49 = call i32 @scp_lock_fork_critical_section_end(i32 %48)
store i32 0, i32* %4
br label %50
50: ; preds = %47, %34, %27
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
define i32 @scp_tcp_force_send(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 (...) @scp_lock_fork_critical_section_start()
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %23
6: ; preds = %3, %19
%7 = phi i8* [ %21, %19 ], [ %1, %3 ]
%8 = phi i32 [ %20, %19 ], [ %2, %3 ]
%9 = tail call i32 @g_tcp_send(i32 %0, i8* %7, i32 %8, i32 0)
switch i32 %9, label %15 [
i32 -1, label %10
i32 0, label %23
]
10: ; preds = %6
%11 = tail call i64 @g_tcp_last_error_would_block(i32 %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %10
%14 = tail call i32 @g_sleep(i32 1)
br label %19
15: ; preds = %6
%16 = sext i32 %9 to i64
%17 = getelementptr inbounds i8, i8* %7, i64 %16
%18 = sub nsw i32 %8, %9
br label %19
19: ; preds = %15, %13
%20 = phi i32 [ %8, %13 ], [ %18, %15 ]
%21 = phi i8* [ %7, %13 ], [ %17, %15 ]
%22 = icmp sgt i32 %20, 0
br i1 %22, label %6, label %23
23: ; preds = %19, %6, %10, %3
%24 = phi i32 [ 0, %3 ], [ 1, %10 ], [ 1, %6 ], [ 0, %19 ]
%25 = tail call i32 @scp_lock_fork_critical_section_end(i32 %4)
ret i32 %24
}