#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 read_byte(int, int);
scalar_t__ tcdrain(int);
int write_byte(int, unsigned char);
int send_packet(int fd, unsigned char packet[], int len) {
  int i;
  for (i = 0; i < len; ++i) {
    if (write_byte(fd, packet[i]) == -1)
      return -1;
    if (i % 8 == 0)
      if (tcdrain(fd) < 0)
        return -1;
  }
  return read_byte(fd, 60 * 1000000);
}


x86 assembly (clang, -O0):
<send_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c8 <send_packet+0x98>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
call   1050 <write_byte@plt>
cmp    $0xffffffff,%eax
jne    117e <send_packet+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <send_packet+0xa8>
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b5 <send_packet+0x85>
mov    -0x8(%rbp),%edi
call   1040 <tcdrain@plt>
cmp    $0x0,%rax
jge    11b0 <send_packet+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <send_packet+0xa8>
jmp    11b5 <send_packet+0x85>
jmp    11ba <send_packet+0x8a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1149 <send_packet+0x19>
mov    -0x8(%rbp),%edi
mov    $0x3938700,%esi
call   1030 <read_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_packet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
test   %edx,%edx
jle    118b <send_packet+0x5b>
mov    %rsi,%r14
mov    %edx,%r15d
xor    %ebx,%ebx
jmp    1159 <send_packet+0x29>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     118b <send_packet+0x5b>
movzbl (%r14,%rbx,1),%esi
mov    %ebp,%edi
call   1050 <write_byte@plt>
cmp    $0xffffffff,%eax
je     117b <send_packet+0x4b>
test   $0x7,%bl
jne    1150 <send_packet+0x20>
mov    %ebp,%edi
call   1040 <tcdrain@plt>
test   %rax,%rax
jns    1150 <send_packet+0x20>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
mov    $0x3938700,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <read_byte@plt>

LLVM IR (-O0):
define i32 @send_packet(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %34, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %37
13: ; preds = %9
%14 = load i32, i32* %5
%15 = load i8*, i8** %6
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @write_byte(i32 %14, i8 zeroext %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 -1, i32* %4
br label %40
23: ; preds = %13
%24 = load i32, i32* %8
%25 = srem i32 %24, 8
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* %5
%29 = call i64 @tcdrain(i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 -1, i32* %4
br label %40
32: ; preds = %27
br label %33
33: ; preds = %32, %23
br label %34
34: ; preds = %33
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %9
37: ; preds = %9
%38 = load i32, i32* %5
%39 = call i32 @read_byte(i32 %38, i32 60000000)
store i32 %39, i32* %4
br label %40
40: ; preds = %37, %31, %22
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
define i32 @send_packet(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %22
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %19
%8 = phi i64 [ 0, %5 ], [ %20, %19 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = tail call i32 @write_byte(i32 %0, i8 zeroext %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %24, label %13
13: ; preds = %7
%14 = and i64 %8, 7
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i64 @tcdrain(i32 %0)
%18 = icmp slt i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %13, %16
%20 = add nuw nsw i64 %8, 1
%21 = icmp eq i64 %20, %6
br i1 %21, label %22, label %7
22: ; preds = %19, %3
%23 = tail call i32 @read_byte(i32 %0, i32 60000000)
br label %24
24: ; preds = %16, %7, %22
%25 = phi i32 [ %23, %22 ], [ -1, %7 ], [ -1, %16 ]
ret i32 %25
}