#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 */
double get_random();
int send_block(int block_size, double e, int max_errors) {
  int errors = 0;
  for (int bit = 0; bit < block_size; bit++) {
    if (get_random() < e)
      errors += 1;
  }
  if (errors > max_errors)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<send_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1172 <send_block+0x62>
mov    $0x0,%al
call   1030 <get_random@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    115f <send_block+0x4f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1164 <send_block+0x54>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <send_block+0x21>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    118a <send_block+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    1191 <send_block+0x81>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_block>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
test   %edi,%edi
jle    114f <send_block+0x3f>
mov    %edi,%ebp
xor    %ebx,%ebx
movsd  %xmm0,0x8(%rsp)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <get_random@plt>
xor    %eax,%eax
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    1130 <send_block+0x20>
jmp    1151 <send_block+0x41>
xor    %ebx,%ebx
xor    %eax,%eax
cmp    %r14d,%ebx
setle  %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @send_block(i32 %0, double %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store double %1, double* %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %22, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = call double (...) @get_random()
%16 = load double, double* %6
%17 = fcmp olt double %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
store i32 %20, i32* %8
br label %21
21: ; preds = %18, %14
br label %22
22: ; preds = %21
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
store i32 %24, i32* %9
br label %10
25: ; preds = %10
%26 = load i32, i32* %8
%27 = load i32, i32* %7
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 0, i32* %4
br label %31
30: ; preds = %25
store i32 1, i32* %4
br label %31
31: ; preds = %30, %29
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @send_block(i32 %0, double %1, i32 %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %9, label %5
5: ; preds = %9, %3
%6 = phi i32 [ 0, %3 ], [ %15, %9 ]
%7 = icmp sle i32 %6, %2
%8 = zext i1 %7 to i32
ret i32 %8
9: ; preds = %3, %9
%10 = phi i32 [ %16, %9 ], [ 0, %3 ]
%11 = phi i32 [ %15, %9 ], [ 0, %3 ]
%12 = tail call double (...) @get_random()
%13 = fcmp olt double %12, %1
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %11, %14
%16 = add nuw nsw i32 %10, 1
%17 = icmp eq i32 %16, %0
br i1 %17, label %5, label %9
}