#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*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ r3d_encrypt_block(unsigned char *, unsigned char *,
                                     unsigned char *);
void r3d_encrypt_ecb(unsigned char *plaintext, unsigned char *key,
                     unsigned char *ciphertext, int size) {
  int block_num = (size / 512);
  unsigned char plaintext_block[512];
  unsigned char ciphertext_block[512];
  unsigned char key_block[512];
  memcpy(key_block, key, 512);
  int i;
  for (i = 0; i < block_num; i++) {
    memcpy(plaintext_block, plaintext + (i * 512), 512);
    r3d_encrypt_block(plaintext_block, key_block, ciphertext_block);
    memcpy(ciphertext + (i * 512), ciphertext_block, 512);
    printf("%d\n", i);
  }
}


x86 assembly (clang, -O0):
<r3d_encrypt_ecb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x630,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
lea    -0x620(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x624(%rbp)
mov    -0x624(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    120c <r3d_encrypt_ecb+0xdc>
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x624(%rbp),%eax
shl    $0x9,%eax
cltq
add    %rax,%rsi
mov    $0x200,%edx
call   1050 <memcpy@plt>
lea    -0x220(%rbp),%rdi
lea    -0x620(%rbp),%rsi
lea    -0x420(%rbp),%rdx
call   1030 <r3d_encrypt_block@plt>
mov    -0x18(%rbp),%rdi
mov    -0x624(%rbp),%eax
shl    $0x9,%eax
cltq
add    %rax,%rdi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
call   1050 <memcpy@plt>
mov    -0x624(%rbp),%esi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x624(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x624(%rbp)
jmp    1177 <r3d_encrypt_ecb+0x47>
add    $0x630,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r3d_encrypt_ecb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x608,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rdi,%r12
mov    %rsp,%rdi
mov    $0x200,%edx
call   1050 <memcpy@plt>
cmp    $0x200,%r14d
jl     11d3 <r3d_encrypt_ecb+0xa3>
shr    $0x9,%r14d
xor    %ebx,%ebx
lea    0x400(%rsp),%r13
lea    0x200(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
mov    $0x200,%edx
call   1050 <memcpy@plt>
mov    %r13,%rdi
mov    %rsp,%rsi
mov    %rbp,%rdx
call   1030 <r3d_encrypt_block@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1050 <memcpy@plt>
lea    0xe4b(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
add    $0x1,%rbx
add    $0x200,%r15
add    $0x200,%r12
cmp    %rbx,%r14
jne    1180 <r3d_encrypt_ecb+0x50>
add    $0x608,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define void @r3d_encrypt_ecb(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca [512 x i8]
%12 = alloca [512 x i8]
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%14 = load i32, i32* %8
%15 = sdiv i32 %14, 512
store i32 %15, i32* %9
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = call i32 @memcpy(i8* %16, i8* %17, i32 512)
store i32 0, i32* %13
br label %19
19: ; preds = %44, %4
%20 = load i32, i32* %13
%21 = load i32, i32* %9
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %47
23: ; preds = %19
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%25 = load i8*, i8** %5
%26 = load i32, i32* %13
%27 = mul nsw i32 %26, 512
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = call i32 @memcpy(i8* %24, i8* %29, i32 512)
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%34 = call i32 @r3d_encrypt_block(i8* %31, i8* %32, i8* %33)
%35 = load i8*, i8** %7
%36 = load i32, i32* %13
%37 = mul nsw i32 %36, 512
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%41 = call i32 @memcpy(i8* %39, i8* %40, i32 512)
%42 = load i32, i32* %13
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %23
%45 = load i32, i32* %13
%46 = add nsw i32 %45, 1
store i32 %46, i32* %13
br label %19
47: ; preds = %19
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define void @r3d_encrypt_ecb(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%11 = call i32 @memcpy(i8* %10, i8* %1, i32 512)
%12 = icmp sgt i32 %3, 511
br i1 %12, label %13, label %28
13: ; preds = %4
%14 = lshr i32 %3, 9
%15 = zext i32 %14 to i64
br label %16
16: ; preds = %13, %16
%17 = phi i64 [ 0, %13 ], [ %26, %16 ]
%18 = shl nsw i64 %17, 9
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = call i32 @memcpy(i8* %8, i8* %19, i32 512)
%21 = call i32 @r3d_encrypt_block(i8* %8, i8* %10, i8* %9)
%22 = getelementptr inbounds i8, i8* %2, i64 %18
%23 = call i32 @memcpy(i8* %22, i8* %9, i32 512)
%24 = trunc i64 %17 to i32
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = add nuw nsw i64 %17, 1
%27 = icmp eq i64 %26, %15
br i1 %27, label %28, label %16
28: ; preds = %16, %4
ret void
}