#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ skytraq_dbg_buf(int /*<<< orphan*/, char const *, int);
int /*<<< orphan*/ skytraq_dbg_newline();
int /*<<< orphan*/ skytraq_dbg_printf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
int write(int, char const *, int);
int skytraq_write(int fd, const char *data, int len) {
  const char *d = data;
  int r;
  int us;
  skytraq_dbg_printf(0, "%4d: ", len);
  if (len < 70)
    skytraq_dbg_buf(0, data, len);
  while (len) {
    int this_time = len;
    if (this_time > 128)
      this_time = 128;
    skytraq_dbg_printf(0, ".");
    fflush(stdout);
    r = write(fd, data, this_time);
    if (r <= 0)
      return r;
    us = r * (1000000 / (57600 / 10 * 9 / 10));
    usleep(r * (1000000 / (57600 / 10 * 9 / 10)));
    data += r;
    len -= r;
  }
  skytraq_dbg_newline();
  return 1;
}


x86 assembly (clang, -O0):
<skytraq_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edx
xor    %edi,%edi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1060 <skytraq_dbg_printf@plt>
cmpl   $0x46,-0x14(%rbp)
jge    11a5 <skytraq_write+0x45>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %edi,%edi
call   1050 <skytraq_dbg_buf@plt>
jmp    11aa <skytraq_write+0x4a>
cmpl   $0x0,-0x14(%rbp)
je     124a <skytraq_write+0xea>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x80,-0x2c(%rbp)
jle    11ce <skytraq_write+0x6e>
movl   $0x80,-0x2c(%rbp)
xor    %edi,%edi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1060 <skytraq_dbg_printf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     1213 <skytraq_write+0xb3>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <skytraq_write+0xf8>
imul   $0xc0,-0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
imul   $0xc0,-0x24(%rbp),%edi
call   1080 <usleep@plt>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    11aa <skytraq_write+0x4a>
mov    $0x0,%al
call   1030 <skytraq_dbg_newline@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skytraq_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r12d
lea    0xe86(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1060 <skytraq_dbg_printf@plt>
cmp    $0x45,%ebx
jg     1198 <skytraq_write+0x38>
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <skytraq_dbg_buf@plt>
test   %ebx,%ebx
je     11fc <skytraq_write+0x9c>
lea    0xe67(%rip),%r15
mov    0x2e3a(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
cmp    $0x80,%ebx
mov    $0x80,%ebp
cmovl  %ebx,%ebp
xor    %edi,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <skytraq_dbg_printf@plt>
mov    0x0(%r13),%edi
call   1070 <fflush@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1208 <skytraq_write+0xa8>
mov    %ebp,%eax
shl    $0x6,%eax
lea    (%rax,%rax,2),%edi
call   1080 <usleep@plt>
mov    %ebp,%eax
add    %rax,%r14
sub    %ebp,%ebx
jne    11b0 <skytraq_write+0x50>
xor    %eax,%eax
call   1030 <skytraq_dbg_newline@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%4d: \00"
@.str.1 = [2 x i8] c".\00"
@stdout = global i32 0
define i32 @skytraq_write(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %6
store i8* %12, i8** %8
%13 = load i32, i32* %7
%14 = call i32 (i32, i8*, ...) @skytraq_dbg_printf(i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 70
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = call i32 @skytraq_dbg_buf(i32 0, i8* %18, i32 %19)
br label %21
21: ; preds = %17, %3
br label %22
22: ; preds = %42, %21
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %55
25: ; preds = %22
%26 = load i32, i32* %7
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = icmp sgt i32 %27, 128
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 128, i32* %11
br label %30
30: ; preds = %29, %25
%31 = call i32 (i32, i8*, ...) @skytraq_dbg_printf(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = load i32, i32* %5
%35 = load i8*, i8** %6
%36 = load i32, i32* %11
%37 = call i32 @write(i32 %34, i8* %35, i32 %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp sle i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %30
%41 = load i32, i32* %9
store i32 %41, i32* %4
br label %57
42: ; preds = %30
%43 = load i32, i32* %9
%44 = mul nsw i32 %43, 192
store i32 %44, i32* %10
%45 = load i32, i32* %9
%46 = mul nsw i32 %45, 192
%47 = call i32 @usleep(i32 %46)
%48 = load i32, i32* %9
%49 = load i8*, i8** %6
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8* %51, i8** %6
%52 = load i32, i32* %9
%53 = load i32, i32* %7
%54 = sub nsw i32 %53, %52
store i32 %54, i32* %7
br label %22
55: ; preds = %22
%56 = call i32 (...) @skytraq_dbg_newline()
store i32 1, i32* %4
br label %57
57: ; preds = %55, %40
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@.str = [6 x i8] c"%4d: \00"
@.str.1 = [2 x i8] c".\00"
@stdout = global i32 0
define i32 @skytraq_write(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 (i32, i8*, ...) @skytraq_dbg_printf(i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %2)
%5 = icmp slt i32 %2, 70
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @skytraq_dbg_buf(i32 0, i8* %1, i32 %2)
%8 = icmp eq i32 %2, 0
br i1 %8, label %27, label %9
9: ; preds = %3, %6
br label %10
10: ; preds = %9, %20
%11 = phi i8* [ %24, %20 ], [ %1, %9 ]
%12 = phi i32 [ %25, %20 ], [ %2, %9 ]
%13 = icmp slt i32 %12, 128
%14 = select i1 %13, i32 %12, i32 128
%15 = tail call i32 (i32, i8*, ...) @skytraq_dbg_printf(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @stdout
%17 = tail call i32 @fflush(i32 %16)
%18 = tail call i32 @write(i32 %0, i8* %11, i32 %14)
%19 = icmp slt i32 %18, 1
br i1 %19, label %29, label %20
20: ; preds = %10
%21 = mul nsw i32 %18, 192
%22 = tail call i32 @usleep(i32 %21)
%23 = zext i32 %18 to i64
%24 = getelementptr inbounds i8, i8* %11, i64 %23
%25 = sub nsw i32 %12, %18
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %10
27: ; preds = %20, %6
%28 = tail call i32 (...) @skytraq_dbg_newline()
br label %29
29: ; preds = %10, %27
%30 = phi i32 [ 1, %27 ], [ %18, %10 ]
ret i32 %30
}