#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 */
typedef int /*<<< orphan*/ chosen_block;

/* Variables and functions */
int aes_detect_ecb_mode(unsigned char *, int /*<<< orphan*/);
int generate_random_aes_mode(unsigned char *, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ strlen(char *);
unsigned int ecb_detection_oracle() {
  unsigned char ciphertext[16 * 15 + 30], chosen_block[16] = "0123456789ABCDEF",
                                          chosen_plaintext[16 * 15 + 1];
  unsigned int i;
  for (i = 0; i < 15; i++)
    memcpy(chosen_plaintext + 16 * i, chosen_block, sizeof(chosen_block));
  chosen_plaintext[16 * 15] = 0x00;
  int gen_mode = generate_random_aes_mode(ciphertext, chosen_plaintext);
  int ret_mode =
      aes_detect_ecb_mode(ciphertext, strlen((char *)chosen_plaintext));
  return 2 * ret_mode + gen_mode;
}


x86 assembly (clang, -O0):
<ecb_detection_oracle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    0xeae(%rip),%rax
mov    %rax,-0x120(%rbp)
mov    0xea8(%rip),%rax
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x224(%rbp)
cmpl   $0xf,-0x224(%rbp)
jae    11b8 <ecb_detection_oracle+0x78>
lea    -0x220(%rbp),%rdi
mov    -0x224(%rbp),%eax
shl    $0x4,%eax
mov    %eax,%eax
add    %rax,%rdi
lea    -0x120(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    1171 <ecb_detection_oracle+0x31>
movb   $0x0,-0x130(%rbp)
lea    -0x110(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1060 <generate_random_aes_mode@plt>
mov    %eax,-0x228(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x238(%rbp)
lea    -0x220(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x238(%rbp),%rdi
mov    %eax,%esi
call   1040 <aes_detect_ecb_mode@plt>
mov    %eax,-0x22c(%rbp)
mov    -0x22c(%rbp),%eax
shl    $0x1,%eax
add    -0x228(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecb_detection_oracle>:
push   %r15
push   %r14
push   %rbx
sub    $0x220,%rsp
movaps 0xead(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%r14
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x30(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x40(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x50(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x60(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x70(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x80(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x90(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0xa0(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0xb0(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0xc0(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0xd0(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0xe0(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0xf0(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
movb   $0x0,0x100(%rsp)
lea    0x110(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <generate_random_aes_mode@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <aes_detect_ecb_mode@plt>
lea    (%rbx,%rax,2),%eax
add    $0x220,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.ecb_detection_oracle.chosen_block = [16 x i8] c"0123456789ABCDEF"
define i32 @ecb_detection_oracle() {
%1 = alloca [270 x i8]
%2 = alloca [16 x i8]
%3 = alloca [241 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [16 x i8]* %2 to i8*
store i32 0, i32* %4
br label %8
8: ; preds = %19, %0
%9 = load i32, i32* %4
%10 = icmp ult i32 %9, 15
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* %4
%14 = mul i32 16, %13
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%18 = call i32 @memcpy(i8* %16, i8* %17, i32 16)
br label %19
19: ; preds = %11
%20 = load i32, i32* %4
%21 = add i32 %20, 1
store i32 %21, i32* %4
br label %8
22: ; preds = %8
%23 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 240
store i8 0, i8* %23
%24 = getelementptr inbounds [270 x i8], [270 x i8]* %1, i64 0, i64 0
%25 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 0
%26 = call i32 @generate_random_aes_mode(i8* %24, i8* %25)
store i32 %26, i32* %5
%27 = getelementptr inbounds [270 x i8], [270 x i8]* %1, i64 0, i64 0
%28 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @aes_detect_ecb_mode(i8* %27, i32 %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = mul nsw i32 2, %31
%33 = load i32, i32* %5
%34 = add nsw i32 %32, %33
ret i32 %34
}

LLVM IR (-O2):
@__const.ecb_detection_oracle.chosen_block = [16 x i8] c"0123456789ABCDEF"
define i32 @ecb_detection_oracle() {
%1 = alloca [270 x i8]
%2 = alloca [16 x i8]
%3 = alloca [241 x i8]
%4 = getelementptr inbounds [270 x i8], [270 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 0
%7 = call i32 @memcpy(i8* %6, i8* %5, i32 16)
%8 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 16
%9 = call i32 @memcpy(i8* %8, i8* %5, i32 16)
%10 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 32
%11 = call i32 @memcpy(i8* %10, i8* %5, i32 16)
%12 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 48
%13 = call i32 @memcpy(i8* %12, i8* %5, i32 16)
%14 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 64
%15 = call i32 @memcpy(i8* %14, i8* %5, i32 16)
%16 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 80
%17 = call i32 @memcpy(i8* %16, i8* %5, i32 16)
%18 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 96
%19 = call i32 @memcpy(i8* %18, i8* %5, i32 16)
%20 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 112
%21 = call i32 @memcpy(i8* %20, i8* %5, i32 16)
%22 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 128
%23 = call i32 @memcpy(i8* %22, i8* %5, i32 16)
%24 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 144
%25 = call i32 @memcpy(i8* %24, i8* %5, i32 16)
%26 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 160
%27 = call i32 @memcpy(i8* %26, i8* %5, i32 16)
%28 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 176
%29 = call i32 @memcpy(i8* %28, i8* %5, i32 16)
%30 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 192
%31 = call i32 @memcpy(i8* %30, i8* %5, i32 16)
%32 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 208
%33 = call i32 @memcpy(i8* %32, i8* %5, i32 16)
%34 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 224
%35 = call i32 @memcpy(i8* %34, i8* %5, i32 16)
%36 = getelementptr inbounds [241 x i8], [241 x i8]* %3, i64 0, i64 240
store i8 0, i8* %36
%37 = call i32 @generate_random_aes_mode(i8* %4, i8* %6)
%38 = call i32 @strlen(i8* %6)
%39 = call i32 @aes_detect_ecb_mode(i8* %4, i32 %38)
%40 = shl nsw i32 %39, 1
%41 = add nsw i32 %40, %37
ret i32 %41
}