#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*/ uint8_t;
struct timeval {
  int dummy;
};
typedef int /*<<< orphan*/ expect;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
unsigned long delta_timeval(struct timeval *, struct timeval *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ memcmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ printf(char *, unsigned long, double);
int tea_bag_size(int);
int /*<<< orphan*/ tea_decrypt(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ tea_encrypt(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  uint8_t buf[72 + 4], expect[72 + 4];
  uint8_t key[16];
  unsigned long delta;
  struct timeval start, end;
  assert(tea_bag_size(66) == 72);
  memset(buf, 'X', sizeof(buf));
  memset(buf, 'a', 66);
  memset(expect, 'X', sizeof(expect));
  memset(expect, 0, 72);
  memset(expect, 'a', 66);
  tea_encrypt(key, buf, 66);
  tea_decrypt(key, buf, 72);
  tea_encrypt(key, buf, 66);
  tea_decrypt(key, buf, 72);
  assert(memcmp(buf, expect, sizeof(buf)) == 0);
  gettimeofday(&start, NULL);
  for (int i = 0; i < 2000000; ++i)
    tea_encrypt(key, buf, 66);
  gettimeofday(&end, NULL);
  delta = delta_timeval(&start, &end);
  printf("TEA Encrypt %luus  %.0fns\n", delta,
         (double)delta * 1000.0 / 2000000);
  gettimeofday(&start, NULL);
  for (int i = 0; i < 2000000; ++i)
    tea_decrypt(key, buf, 72);
  gettimeofday(&end, NULL);
  delta = delta_timeval(&start, &end);
  printf("TEA Decrypt %luus  %.0fns\n", delta,
         (double)delta * 1000.0 / 2000000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x42,%edi
call   1030 <tea_bag_size@plt>
cmp    $0x48,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x140(%rbp),%rdi
mov    $0x58,%esi
mov    $0x130,%edx
call   1060 <memset@plt>
lea    -0x140(%rbp),%rdi
mov    $0x61,%esi
mov    $0x42,%edx
call   1060 <memset@plt>
lea    -0x270(%rbp),%rdi
mov    $0x58,%esi
mov    $0x130,%edx
call   1060 <memset@plt>
lea    -0x270(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1060 <memset@plt>
lea    -0x270(%rbp),%rdi
mov    $0x61,%esi
mov    $0x42,%edx
call   1060 <memset@plt>
lea    -0x2b0(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x42,%edx
call   10b0 <tea_encrypt@plt>
lea    -0x2b0(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x48,%edx
call   10a0 <tea_decrypt@plt>
lea    -0x2b0(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x42,%edx
call   10b0 <tea_encrypt@plt>
lea    -0x2b0(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x48,%edx
call   10a0 <tea_decrypt@plt>
lea    -0x140(%rbp),%rdi
lea    -0x270(%rbp),%rsi
mov    $0x130,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x2c0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x2cc(%rbp)
cmpl   $0x1e8480,-0x2cc(%rbp)
jge    130d <main+0x17d>
lea    -0x2b0(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x42,%edx
call   10b0 <tea_encrypt@plt>
mov    -0x2cc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2cc(%rbp)
jmp    12d1 <main+0x141>
xor    %eax,%eax
mov    %eax,%esi
lea    -0x2c8(%rbp),%rdi
mov    %rdi,-0x2d8(%rbp)
call   1050 <gettimeofday@plt>
mov    -0x2d8(%rbp),%rsi
lea    -0x2c0(%rbp),%rdi
call   1090 <delta_timeval@plt>
mov    %rax,-0x2b8(%rbp)
mov    -0x2b8(%rbp),%rsi
movq   %rsi,%xmm0
movaps 0xcbf(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xcc3(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xc94(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xc80(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xca5(%rip),%rdi
call   1040 <printf@plt>
lea    -0x2c0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x2d0(%rbp)
cmpl   $0x1e8480,-0x2d0(%rbp)
jge    13e6 <main+0x256>
lea    -0x2b0(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x48,%edx
call   10a0 <tea_decrypt@plt>
mov    -0x2d0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2d0(%rbp)
jmp    13aa <main+0x21a>
xor    %eax,%eax
mov    %eax,%esi
lea    -0x2c8(%rbp),%rdi
mov    %rdi,-0x2e0(%rbp)
call   1050 <gettimeofday@plt>
mov    -0x2e0(%rbp),%rsi
lea    -0x2c0(%rbp),%rdi
call   1090 <delta_timeval@plt>
mov    %rax,-0x2b8(%rbp)
mov    -0x2b8(%rbp),%rsi
movq   %rsi,%xmm0
movaps 0xbe6(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xbea(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xbbb(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xba7(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xbe7(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x2e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2b8,%rsp
mov    $0x42,%edi
call   1030 <tea_bag_size@plt>
xor    %edi,%edi
cmp    $0x48,%eax
sete   %dil
call   1080 <assert@plt>
lea    0x50(%rsp),%r14
mov    %r14,%rdi
mov    $0x58,%esi
mov    $0x130,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    $0x61,%esi
mov    $0x42,%edx
call   1060 <memset@plt>
lea    0x180(%rsp),%r15
mov    %r15,%rdi
mov    $0x58,%esi
mov    $0x130,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    $0x61,%esi
mov    $0x42,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x42,%edx
call   10b0 <tea_encrypt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x48,%edx
call   10a0 <tea_decrypt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x42,%edx
call   10b0 <tea_encrypt@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x48,%edx
call   10a0 <tea_decrypt@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x130,%edx
call   1070 <memcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x1e8480,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x42,%edx
call   10b0 <tea_encrypt@plt>
add    $0xffffffff,%ebp
jne    1290 <main+0x100>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <delta_timeval@plt>
movq   %rax,%xmm1
punpckldq 0xd31(%rip),%xmm1
subpd  0xd39(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xd35(%rip),%xmm0
divsd  0xd35(%rip),%xmm0
lea    0xd36(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x1e8480,%ebp
lea    0x10(%rsp),%r14
lea    0x50(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x48,%edx
call   10a0 <tea_decrypt@plt>
add    $0xffffffff,%ebp
jne    1320 <main+0x190>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1090 <delta_timeval@plt>
movq   %rax,%xmm1
punpckldq 0xca4(%rip),%xmm1
subpd  0xcac(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xca8(%rip),%xmm0
divsd  0xca8(%rip),%xmm0
lea    0xcc4(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x2b8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [27 x i8] c"TEA Encrypt %luus %.0fns\0A\00"
@.str.1 = [27 x i8] c"TEA Decrypt %luus %.0fns\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [76 x i32]
%7 = alloca [76 x i32]
%8 = alloca [16 x i32]
%9 = alloca i64
%10 = alloca %struct.timeval
%11 = alloca %struct.timeval
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 @tea_bag_size(i32 66)
%15 = icmp eq i32 %14, 72
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = getelementptr inbounds [76 x i32], [76 x i32]* %6, i64 0, i64 0
%19 = call i32 @memset(i32* %18, i8 signext 88, i32 304)
%20 = getelementptr inbounds [76 x i32], [76 x i32]* %6, i64 0, i64 0
%21 = call i32 @memset(i32* %20, i8 signext 97, i32 66)
%22 = getelementptr inbounds [76 x i32], [76 x i32]* %7, i64 0, i64 0
%23 = call i32 @memset(i32* %22, i8 signext 88, i32 304)
%24 = getelementptr inbounds [76 x i32], [76 x i32]* %7, i64 0, i64 0
%25 = call i32 @memset(i32* %24, i8 signext 0, i32 72)
%26 = getelementptr inbounds [76 x i32], [76 x i32]* %7, i64 0, i64 0
%27 = call i32 @memset(i32* %26, i8 signext 97, i32 66)
%28 = getelementptr inbounds [16 x i32], [16 x i32]* %8, i64 0, i64 0
%29 = getelementptr inbounds [76 x i32], [76 x i32]* %6, i64 0, i64 0
%30 = call i32 @tea_encrypt(i32* %28, i32* %29, i32 66)
%31 = getelementptr inbounds [16 x i32], [16 x i32]* %8, i64 0, i64 0
%32 = getelementptr inbounds [76 x i32], [76 x i32]* %6, i64 0, i64 0
%33 = call i32 @tea_decrypt(i32* %31, i32* %32, i32 72)
%34 = getelementptr inbounds [16 x i32], [16 x i32]* %8, i64 0, i64 0
%35 = getelementptr inbounds [76 x i32], [76 x i32]* %6, i64 0, i64 0
%36 = call i32 @tea_encrypt(i32* %34, i32* %35, i32 66)
%37 = getelementptr inbounds [16 x i32], [16 x i32]* %8, i64 0, i64 0
%38 = getelementptr inbounds [76 x i32], [76 x i32]* %6, i64 0, i64 0
%39 = call i32 @tea_decrypt(i32* %37, i32* %38, i32 72)
%40 = getelementptr inbounds [76 x i32], [76 x i32]* %6, i64 0, i64 0
%41 = getelementptr inbounds [76 x i32], [76 x i32]* %7, i64 0, i64 0
%42 = call i64 @memcmp(i32* %40, i32* %41, i32 304)
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
store i32 0, i32* %12
br label %47
47: ; preds = %54, %2
%48 = load i32, i32* %12
%49 = icmp slt i32 %48, 2000000
br i1 %49, label %50, label %57
50: ; preds = %47
%51 = getelementptr inbounds [16 x i32], [16 x i32]* %8, i64 0, i64 0
%52 = getelementptr inbounds [76 x i32], [76 x i32]* %6, i64 0, i64 0
%53 = call i32 @tea_encrypt(i32* %51, i32* %52, i32 66)
br label %54
54: ; preds = %50
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %12
br label %47
57: ; preds = %47
%58 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
%59 = call i64 @delta_timeval(%struct.timeval* %10, %struct.timeval* %11)
store i64 %59, i64* %9
%60 = load i64, i64* %9
%61 = load i64, i64* %9
%62 = uitofp i64 %61 to double
%63 = fmul double %62, 1.000000e+03
%64 = fdiv double %63, 2.000000e+06
%65 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %60, double %64)
%66 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
store i32 0, i32* %13
br label %67
67: ; preds = %74, %57
%68 = load i32, i32* %13
%69 = icmp slt i32 %68, 2000000
br i1 %69, label %70, label %77
70: ; preds = %67
%71 = getelementptr inbounds [16 x i32], [16 x i32]* %8, i64 0, i64 0
%72 = getelementptr inbounds [76 x i32], [76 x i32]* %6, i64 0, i64 0
%73 = call i32 @tea_decrypt(i32* %71, i32* %72, i32 72)
br label %74
74: ; preds = %70
%75 = load i32, i32* %13
%76 = add nsw i32 %75, 1
store i32 %76, i32* %13
br label %67
77: ; preds = %67
%78 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
%79 = call i64 @delta_timeval(%struct.timeval* %10, %struct.timeval* %11)
store i64 %79, i64* %9
%80 = load i64, i64* %9
%81 = load i64, i64* %9
%82 = uitofp i64 %81 to double
%83 = fmul double %82, 1.000000e+03
%84 = fdiv double %83, 2.000000e+06
%85 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %80, double %84)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [27 x i8] c"TEA Encrypt %luus %.0fns\0A\00"
@.str.1 = [27 x i8] c"TEA Decrypt %luus %.0fns\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [76 x i32]
%4 = alloca [76 x i32]
%5 = alloca [16 x i32]
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = bitcast [76 x i32]* %3 to i8*
%9 = bitcast [76 x i32]* %4 to i8*
%10 = bitcast [16 x i32]* %5 to i8*
%11 = bitcast %struct.timeval* %6 to i8*
%12 = bitcast %struct.timeval* %7 to i8*
%13 = tail call i32 @tea_bag_size(i32 66)
%14 = icmp eq i32 %13, 72
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = getelementptr inbounds [76 x i32], [76 x i32]* %3, i64 0, i64 0
%18 = call i32 @memset(i32* %17, i8 signext 88, i32 304)
%19 = call i32 @memset(i32* %17, i8 signext 97, i32 66)
%20 = getelementptr inbounds [76 x i32], [76 x i32]* %4, i64 0, i64 0
%21 = call i32 @memset(i32* %20, i8 signext 88, i32 304)
%22 = call i32 @memset(i32* %20, i8 signext 0, i32 72)
%23 = call i32 @memset(i32* %20, i8 signext 97, i32 66)
%24 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%25 = call i32 @tea_encrypt(i32* %24, i32* %17, i32 66)
%26 = call i32 @tea_decrypt(i32* %24, i32* %17, i32 72)
%27 = call i32 @tea_encrypt(i32* %24, i32* %17, i32 66)
%28 = call i32 @tea_decrypt(i32* %24, i32* %17, i32 72)
%29 = call i64 @memcmp(i32* %17, i32* %20, i32 304)
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
br label %42
34: ; preds = %42
%35 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%36 = call i64 @delta_timeval(%struct.timeval* %6, %struct.timeval* %7)
%37 = uitofp i64 %36 to double
%38 = fmul double %37, 1.000000e+03
%39 = fdiv double %38, 2.000000e+06
%40 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %36, double %39)
%41 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
br label %54
42: ; preds = %2, %42
%43 = phi i32 [ 0, %2 ], [ %45, %42 ]
%44 = call i32 @tea_encrypt(i32* %24, i32* %17, i32 66)
%45 = add nuw nsw i32 %43, 1
%46 = icmp eq i32 %45, 2000000
br i1 %46, label %34, label %42
47: ; preds = %54
%48 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%49 = call i64 @delta_timeval(%struct.timeval* %6, %struct.timeval* %7)
%50 = uitofp i64 %49 to double
%51 = fmul double %50, 1.000000e+03
%52 = fdiv double %51, 2.000000e+06
%53 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %49, double %52)
ret i32 0
54: ; preds = %34, %54
%55 = phi i32 [ 0, %34 ], [ %57, %54 ]
%56 = call i32 @tea_decrypt(i32* %24, i32* %17, i32 72)
%57 = add nuw nsw i32 %55, 1
%58 = icmp eq i32 %57, 2000000
br i1 %58, label %47, label %54
}