#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ decrypt(int *, int *);
int /*<<< orphan*/ encrypt(int *, int *);
int /*<<< orphan*/ printf(char *, ...);
void main(int argc, char **argv) {
  uint32_t i;
  uint32_t s0, s1;
  uint32_t k[] = {0, 0, 0, 0};
  uint32_t v[] = {0, 0};
  printf("i #                k               #       pt       #        ct      "
         "\n");
  for (i = 0; i < 100; i++) {
    printf("%02X %08X%08X%08X%08X ", i, k[0], k[1], k[2], k[3]);
    printf("%08X%08X ", v[0], v[1]);
    encrypt(v, k);
    s0 = v[0];
    s1 = v[1];
    printf("%08X%08X\n", v[0], v[1]);
    decrypt(v, k);
    k[2 + (i % 2)] ^= s0;
    k[1 - (i % 2)] ^= s1;
    v[0] = s0;
    v[1] = s1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    1250 <main+0x110>
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <encrypt@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <decrypt@plt>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
add    $0x2,%edx
movslq %edx,%rax
xor    -0x30(%rbp,%rax,4),%ecx
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x1c(%rbp),%ecx
mov    -0x14(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    $0x1,%eax
sub    %edx,%eax
cltq
xor    -0x30(%rbp,%rax,4),%ecx
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <main+0x44>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xebb(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%rbx
lea    0xe9b(%rip),%r13
xor    %r9d,%r9d
xor    %r8d,%r8d
xor    %ecx,%ecx
xor    %edx,%edx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    0xe69(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <encrypt@plt>
mov    0x8(%rsp),%r14d
mov    0xc(%rsp),%r15d
mov    %r13,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <decrypt@plt>
mov    %ebp,%eax
and    $0x1,%eax
lea    0x2(%rax),%ecx
xor    %r14d,0x10(%rsp,%rcx,4)
xor    $0x1,%eax
xor    %r15d,0x10(%rsp,%rax,4)
mov    %r14d,0x8(%rsp)
mov    %r15d,0xc(%rsp)
cmp    $0x63,%ebp
je     1224 <main+0xe4>
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    0x18(%rsp),%r8d
mov    0x1c(%rsp),%r9d
add    $0x1,%ebp
jmp    1190 <main+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [71 x i8] c"i # k # pt # ct \0A\00"
@.str.1 = [23 x i8] c"%02X %08X%08X%08X%08X \00"
@.str.2 = [10 x i8] c"%08X%08X \00"
@.str.3 = [10 x i8] c"%08X%08X\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i32]
%9 = alloca [2 x i32]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = bitcast [4 x i32]* %8 to i8*
%11 = bitcast [2 x i32]* %9 to i8*
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %13
13: ; preds = %67, %2
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 100
br i1 %15, label %16, label %70
16: ; preds = %13
%17 = load i32, i32* %5
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 2
%23 = load i32, i32* %22
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 3
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %19, i32 %21, i32 %23, i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%34 = call i32 @encrypt(i32* %32, i32* %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%36 = load i32, i32* %35
store i32 %36, i32* %6
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%38 = load i32, i32* %37
store i32 %38, i32* %7
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%40 = load i32, i32* %39
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %42)
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%46 = call i32 @decrypt(i32* %44, i32* %45)
%47 = load i32, i32* %6
%48 = load i32, i32* %5
%49 = srem i32 %48, 2
%50 = add nsw i32 2, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = xor i32 %53, %47
store i32 %54, i32* %52
%55 = load i32, i32* %7
%56 = load i32, i32* %5
%57 = srem i32 %56, 2
%58 = sub nsw i32 1, %57
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 %59
%61 = load i32, i32* %60
%62 = xor i32 %61, %55
store i32 %62, i32* %60
%63 = load i32, i32* %6
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
store i32 %63, i32* %64
%65 = load i32, i32* %7
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
store i32 %65, i32* %66
br label %67
67: ; preds = %16
%68 = load i32, i32* %5
%69 = add nsw i32 %68, 1
store i32 %69, i32* %5
br label %13
70: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"%02X %08X%08X%08X%08X \00"
@.str.2 = [10 x i8] c"%08X%08X \00"
@.str.3 = [10 x i8] c"%08X%08X\0A\00"
@str = [70 x i8] c"i # k # pt # ct \00"
define void @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x i32]
%4 = alloca i64
%5 = bitcast i64* %4 to [2 x i32]*
%6 = bitcast [4 x i32]* %3 to i8*
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%13 = bitcast i64* %4 to i32*
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
br label %15
15: ; preds = %43, %2
%16 = phi i32 [ 0, %2 ], [ %47, %43 ]
%17 = phi i32 [ 0, %2 ], [ %46, %43 ]
%18 = phi i32 [ 0, %2 ], [ %45, %43 ]
%19 = phi i32 [ 0, %2 ], [ %44, %43 ]
%20 = phi i32 [ 0, %2 ], [ %41, %43 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %19, i32 %18, i32 %17, i32 %16)
%22 = load i32, i32* %13
%23 = load i32, i32* %14
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %23)
%25 = call i32 @encrypt(i32* %13, i32* %9)
%26 = load i32, i32* %13
%27 = load i32, i32* %14
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27)
%29 = call i32 @decrypt(i32* %13, i32* %9)
%30 = and i32 %20, 1
%31 = or i32 %30, 2
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = xor i32 %34, %26
store i32 %35, i32* %33
%36 = xor i32 %30, 1
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = xor i32 %39, %27
store i32 %40, i32* %38
store i32 %26, i32* %13
store i32 %27, i32* %14
%41 = add nuw nsw i32 %20, 1
%42 = icmp eq i32 %41, 100
br i1 %42, label %48, label %43
43: ; preds = %15
%44 = load i32, i32* %9
%45 = load i32, i32* %10
%46 = load i32, i32* %11
%47 = load i32, i32* %12
br label %15
48: ; preds = %15
ret void
}