#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*/ perror(char *);
int rand();
int /*<<< orphan*/ usleep(int);
int write(int, char const *, int);
void send_response(int c, const char *buffer, int len) {
  int n;
  while (len > 0) {
    n = (rand() % 99) + 1;
    if (n > len)
      n = len;
    n = write(c, buffer, n);
    if (n < 0) {
      perror("write");
      return;
    } else {
      len -= n;
      buffer += n;
    }
    usleep(10000);
  }
}


x86 assembly (clang, -O0):
<send_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11db <send_response+0x9b>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x63,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1183 <send_response+0x43>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11b0 <send_response+0x70>
lea    0xe5a(%rip),%rdi
call   1040 <perror@plt>
jmp    11db <send_response+0x9b>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    $0x2710,%edi
call   1060 <usleep@plt>
jmp    1152 <send_response+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_response>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    11b8 <send_response+0x78>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0xffffffffa57eb503,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x63,%ecx,%ecx
mov    %eax,%esi
sub    %ecx,%esi
neg    %ecx
lea    (%rax,%rcx,1),%edx
add    $0x1,%edx
cmp    %ebx,%esi
cmovge %ebx,%edx
mov    %r15d,%edi
mov    %r14,%rsi
call   1030 <write@plt>
test   %eax,%eax
js     11c3 <send_response+0x83>
mov    %eax,%ebp
mov    %eax,%eax
add    %rax,%r14
mov    $0x2710,%edi
call   1060 <usleep@plt>
sub    %ebp,%ebx
jg     1160 <send_response+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe36(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <perror@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"write\00"
define void @send_response(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %37, %3
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %39
11: ; preds = %8
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 99
%14 = add nsw i32 %13, 1
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = load i32, i32* %6
store i32 %19, i32* %7
br label %20
20: ; preds = %18, %11
%21 = load i32, i32* %4
%22 = load i8*, i8** %5
%23 = load i32, i32* %7
%24 = call i32 @write(i32 %21, i8* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %39
29: ; preds = %20
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = sub nsw i32 %31, %30
store i32 %32, i32* %6
%33 = load i32, i32* %7
%34 = load i8*, i8** %5
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8* %36, i8** %5
br label %37
37: ; preds = %29
%38 = call i32 @usleep(i32 10000)
br label %8
39: ; preds = %27, %8
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"write\00"
define void @send_response(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %23
5: ; preds = %3, %17
%6 = phi i32 [ %18, %17 ], [ %2, %3 ]
%7 = phi i8* [ %20, %17 ], [ %1, %3 ]
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 99
%10 = add nsw i32 %9, 1
%11 = icmp slt i32 %9, %6
%12 = select i1 %11, i32 %10, i32 %6
%13 = tail call i32 @write(i32 %0, i8* %7, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %5
%16 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %23
17: ; preds = %5
%18 = sub nsw i32 %6, %13
%19 = zext i32 %13 to i64
%20 = getelementptr inbounds i8, i8* %7, i64 %19
%21 = tail call i32 @usleep(i32 10000)
%22 = icmp sgt i32 %18, 0
br i1 %22, label %5, label %23
23: ; preds = %17, %3, %15
ret void
}