#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 */
unsigned int ecb_detection_oracle();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  srand(time(NULL));
  unsigned int i, r, results[4] = {0};
  for (i = 0; i < 1000; i++) {
    r = ecb_detection_oracle();
    results[r % 4]++;
  }
  printf("Results :\n");
  printf("ret\\gen      cbc, ecb\n");
  printf("cbc	%lf, %lf\n", results[0] / ((float)results[0] + results[2]),
         results[1] / ((float)results[1] + results[3]));
  printf("ecb	%lf, %lf\n", results[2] / ((float)results[0] + results[2]),
         results[3] / ((float)results[1] + results[3]));
  return 0x00;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jae    11c5 <main+0x75>
mov    $0x0,%al
call   1070 <ecb_detection_oracle@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
mov    -0x30(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x3d>
lea    0xe34(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x31(%rbp)
call   1030 <printf@plt>
mov    -0x31(%rbp),%al
lea    0xe2b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%eax
cvtsi2ss %rcx,%xmm0
mov    -0x28(%rbp),%ecx
cvtsi2ss %rcx,%xmm2
movaps %xmm0,%xmm1
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
mov    -0x24(%rbp),%eax
cvtsi2ss %rax,%xmm3
movaps %xmm1,%xmm2
addss  %xmm3,%xmm2
divss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xdf8(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
cvtsi2ss %rax,%xmm0
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%eax
cvtsi2ss %rcx,%xmm1
addss  %xmm0,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x24(%rbp),%ecx
cvtsi2ss %rcx,%xmm1
cvtsi2ss %rax,%xmm2
movaps %xmm1,%xmm3
addss  %xmm3,%xmm2
divss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xdbd(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x3e8,%ebx
xor    %eax,%eax
call   1070 <ecb_detection_oracle@plt>
and    $0x3,%eax
addl   $0x1,0x10(%rsp,%rax,4)
add    $0xffffffff,%ebx
jne    1170 <main+0x20>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%eax
mov    0x14(%rsp),%ecx
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mov    0x18(%rsp),%eax
cvtsi2ss %rax,%xmm1
movss  %xmm1,0xc(%rsp)
movaps %xmm0,%xmm2
addss  %xmm1,%xmm2
movss  %xmm2,0x8(%rsp)
divss  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %rcx,%xmm1
mov    0x1c(%rsp),%eax
xorps  %xmm2,%xmm2
cvtsi2ss %rax,%xmm2
movss  %xmm2,0x4(%rsp)
cvtss2sd %xmm0,%xmm0
movaps %xmm1,%xmm3
addss  %xmm2,%xmm3
movss  %xmm3,(%rsp)
divss  %xmm3,%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xdfb(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm0
divss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
divss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xddc(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Results :\0A\00"
@.str.1 = [23 x i8] c"ret\\gen cbc, ecb\0A\00"
@.str.2 = [14 x i8] c"cbc\09%lf, %lf\0A\00"
@.str.3 = [14 x i8] c"ecb\09%lf, %lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
%11 = bitcast [4 x i32]* %8 to i8*
store i32 0, i32* %6
br label %12
12: ; preds = %23, %2
%13 = load i32, i32* %6
%14 = icmp ult i32 %13, 1000
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = call i32 (...) @ecb_detection_oracle()
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = urem i32 %17, 4
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = add i32 %21, 1
store i32 %22, i32* %20
br label %23
23: ; preds = %15
%24 = load i32, i32* %6
%25 = add i32 %24, 1
store i32 %25, i32* %6
br label %12
26: ; preds = %12
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%30 = load i32, i32* %29
%31 = uitofp i32 %30 to float
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%33 = load i32, i32* %32
%34 = uitofp i32 %33 to float
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
%36 = load i32, i32* %35
%37 = uitofp i32 %36 to float
%38 = fadd float %34, %37
%39 = fdiv float %31, %38
%40 = fpext float %39 to double
%41 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
%42 = load i32, i32* %41
%43 = uitofp i32 %42 to float
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
%45 = load i32, i32* %44
%46 = uitofp i32 %45 to float
%47 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 3
%48 = load i32, i32* %47
%49 = uitofp i32 %48 to float
%50 = fadd float %46, %49
%51 = fdiv float %43, %50
%52 = fpext float %51 to double
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %40, double %52)
%54 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
%55 = load i32, i32* %54
%56 = uitofp i32 %55 to float
%57 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%58 = load i32, i32* %57
%59 = uitofp i32 %58 to float
%60 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
%61 = load i32, i32* %60
%62 = uitofp i32 %61 to float
%63 = fadd float %59, %62
%64 = fdiv float %56, %63
%65 = fpext float %64 to double
%66 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 3
%67 = load i32, i32* %66
%68 = uitofp i32 %67 to float
%69 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
%70 = load i32, i32* %69
%71 = uitofp i32 %70 to float
%72 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 3
%73 = load i32, i32* %72
%74 = uitofp i32 %73 to float
%75 = fadd float %71, %74
%76 = fdiv float %68, %75
%77 = fpext float %76 to double
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %65, double %77)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [14 x i8] c"cbc\09%lf, %lf\0A\00"
@.str.3 = [14 x i8] c"ecb\09%lf, %lf\0A\00"
@str = [10 x i8] c"Results :\00"
@str.4 = [22 x i8] c"ret\\gen cbc, ecb\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x i32]
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = bitcast [4 x i32]* %3 to i8*
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %15, %7 ]
%9 = tail call i32 (...) @ecb_detection_oracle()
%10 = and i32 %9, 3
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = add i32 %13, 1
store i32 %14, i32* %12
%15 = add nuw nsw i32 %8, 1
%16 = icmp eq i32 %15, 1000
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0))
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%21 = load i32, i32* %20
%22 = uitofp i32 %21 to float
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%24 = load i32, i32* %23
%25 = uitofp i32 %24 to float
%26 = fadd float %22, %25
%27 = fdiv float %22, %26
%28 = fpext float %27 to double
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%30 = load i32, i32* %29
%31 = uitofp i32 %30 to float
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%33 = load i32, i32* %32
%34 = uitofp i32 %33 to float
%35 = fadd float %31, %34
%36 = fdiv float %31, %35
%37 = fpext float %36 to double
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %28, double %37)
%39 = fdiv float %25, %26
%40 = fpext float %39 to double
%41 = fdiv float %34, %35
%42 = fpext float %41 to double
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %40, double %42)
ret i32 0
}