#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 */
scalar_t__ transmit(int, char *, size_t, size_t *);
int send_n_bytes(int fd, char *buf, size_t n) {
  size_t nsent = 0;
  size_t tx_amt = 0;
  while (n > 0) {
    if (transmit(fd, buf + nsent, n - nsent < 64 ? n - nsent : 64, &tx_amt) !=
        0)
      return -1;
    n -= tx_amt;
  }
  return 0;
}


x86 assembly (clang, -O0):
<send_n_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11bf <send_n_bytes+0xaf>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
cmp    $0x40,%rax
jae    1173 <send_n_bytes+0x63>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1181 <send_n_bytes+0x71>
mov    $0x40,%eax
mov    %rax,-0x40(%rbp)
jmp    1181 <send_n_bytes+0x71>
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edi
mov    -0x40(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <transmit@plt>
cmp    $0x0,%rax
je     11ab <send_n_bytes+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <send_n_bytes+0xb6>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1133 <send_n_bytes+0x23>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_n_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
xor    %r14d,%r14d
test   %rdx,%rdx
je     116e <send_n_bytes+0x5e>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%ebp
lea    0x8(%rsp),%r12
nopw   0x0(%rax,%rax,1)
cmp    $0x40,%rbx
mov    $0x40,%edx
cmovb  %rbx,%rdx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rcx
call   1030 <transmit@plt>
test   %rax,%rax
jne    1168 <send_n_bytes+0x58>
sub    0x8(%rsp),%rbx
jne    1140 <send_n_bytes+0x30>
jmp    116e <send_n_bytes+0x5e>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @send_n_bytes(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
br label %10
10: ; preds = %32, %3
%11 = load i64, i64* %7
%12 = icmp ugt i64 %11, 0
br i1 %12, label %13, label %36
13: ; preds = %10
%14 = load i32, i32* %5
%15 = load i8*, i8** %6
%16 = load i64, i64* %8
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = load i64, i64* %7
%19 = load i64, i64* %8
%20 = sub i64 %18, %19
%21 = icmp ult i64 %20, 64
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = load i64, i64* %7
%24 = load i64, i64* %8
%25 = sub i64 %23, %24
br label %27
26: ; preds = %13
br label %27
27: ; preds = %26, %22
%28 = phi i64 [ %25, %22 ], [ 64, %26 ]
%29 = call i64 @transmit(i32 %14, i8* %17, i64 %28, i64* %9)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 -1, i32* %4
br label %37
32: ; preds = %27
%33 = load i64, i64* %9
%34 = load i64, i64* %7
%35 = sub i64 %34, %33
store i64 %35, i64* %7
br label %10
36: ; preds = %10
store i32 0, i32* %4
br label %37
37: ; preds = %36, %31
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
define i32 @send_n_bytes(i32 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%6 = icmp eq i64 %2, 0
br i1 %6, label %17, label %7
7: ; preds = %3, %13
%8 = phi i64 [ %15, %13 ], [ %2, %3 ]
%9 = icmp ult i64 %8, 64
%10 = select i1 %9, i64 %8, i64 64
%11 = call i64 @transmit(i32 %0, i8* %1, i64 %10, i64* %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = load i64, i64* %4
%15 = sub i64 %8, %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %7, %13, %3
%18 = phi i32 [ 0, %3 ], [ 0, %13 ], [ -1, %7 ]
ret i32 %18
}