#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*/ TEA_decrypt(int *, int, int *);
int /*<<< orphan*/ TEA_encrypt(int *, int, int *);
int /*<<< orphan*/ Usage();
int fread(int *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *, int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (argc != 3)
    Usage();
  uint32_t key[4] = {};
  sscanf(argv[2], "%08x%08x%08x%08x", &key[0], &key[1], &key[2], &key[3]);
  uint32_t buffer[1024];
  if (strcmp(argv[1], "--encrypt") == 0) {
    for (;;) {
      buffer[0] = fread(buffer + 1, 1, 1024 * 4 - 4, stdin);
      if (buffer[0] == 0)
        break;
      TEA_encrypt(buffer, 1024, key);
      fwrite(buffer, 4, 1024, stdout);
    }
  } else if (strcmp(argv[1], "--decrypt") == 0) {
    for (;;) {
      fread(buffer, 4, 1024, stdin);
      TEA_decrypt(buffer, 1024, key);
      fwrite(buffer + 1, 1, buffer[0], stdout);
      if (buffer[0] < 1024 - 1)
        break;
    }
  } else {
    Usage();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11aa <main+0x2a>
mov    $0x0,%al
call   1060 <Usage@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rdx
lea    -0x20(%rbp),%rcx
add    $0x4,%rcx
lea    -0x20(%rbp),%r8
add    $0x8,%r8
lea    -0x20(%rbp),%r9
add    $0xc,%r9
lea    0xe1b(%rip),%rsi
call   1080 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe18(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1286 <main+0x106>
jmp    120d <main+0x8d>
lea    -0x1020(%rbp),%rdi
add    $0x4,%rdi
mov    0x2dc9(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0xffc,%edx
call   1030 <fread@plt>
mov    %eax,-0x1020(%rbp)
cmpl   $0x0,-0x1020(%rbp)
jne    1248 <main+0xc8>
jmp    1281 <main+0x101>
lea    -0x1020(%rbp),%rdi
lea    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1040 <TEA_encrypt@plt>
lea    -0x1020(%rbp),%rdi
mov    0x2d6d(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%esi
mov    $0x400,%edx
call   10a0 <fwrite@plt>
jmp    120d <main+0x8d>
jmp    132c <main+0x1ac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd86(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1320 <main+0x1a0>
jmp    12a9 <main+0x129>
lea    -0x1020(%rbp),%rdi
mov    0x2d31(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1090 <TEA_decrypt@plt>
lea    -0x1020(%rbp),%rdi
add    $0x4,%rdi
mov    -0x1020(%rbp),%edx
mov    0x2ce3(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
cmpl   $0x3ff,-0x1020(%rbp)
jge    1316 <main+0x196>
jmp    131b <main+0x19b>
jmp    12a9 <main+0x129>
jmp    1327 <main+0x1a7>
mov    $0x0,%al
call   1060 <Usage@plt>
jmp    132c <main+0x1ac>
xor    %eax,%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1010,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     118f <main+0x1f>
xor    %eax,%eax
call   1050 <Usage@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x10(%rbx),%rdi
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0xe50(%rip),%rsi
mov    %rsp,%rdx
call   1070 <sscanf@plt>
mov    0x8(%rbx),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f2 <main+0x82>
mov    0x8(%rbx),%rdi
lea    0xe43(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1276 <main+0x106>
xor    %eax,%eax
call   1050 <Usage@plt>
jmp    12e5 <main+0x175>
lea    0x14(%rsp),%r14
mov    0x2dea(%rip),%r12
mov    (%r12),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xffc,%edx
call   1030 <fread@plt>
mov    %eax,0x10(%rsp)
test   %eax,%eax
je     12e5 <main+0x175>
lea    0x10(%rsp),%rbx
mov    %rsp,%r15
mov    0x2da9(%rip),%r13
nop
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1040 <TEA_encrypt@plt>
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x400,%edx
call   1090 <fwrite@plt>
mov    (%r12),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xffc,%edx
call   1030 <fread@plt>
mov    %eax,0x10(%rsp)
test   %eax,%eax
jne    1230 <main+0xc0>
jmp    12e5 <main+0x175>
lea    0x14(%rsp),%r14
mov    0x2d66(%rip),%r12
lea    0x10(%rsp),%rbx
mov    %rsp,%r15
mov    0x2d47(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r12),%ecx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1080 <TEA_decrypt@plt>
mov    0x10(%rsp),%edx
mov    0x0(%r13),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
call   1090 <fwrite@plt>
cmpl   $0x3ff,0x10(%rsp)
jge    12a0 <main+0x130>
xor    %eax,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"%08x%08x%08x%08x\00"
@.str.1 = [10 x i8] c"--encrypt\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [10 x i8] c"--decrypt\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i32]
%7 = alloca [1024 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @Usage()
br label %12
12: ; preds = %10, %2
%13 = bitcast [4 x i32]* %6 to i8*
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 1
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 2
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 3
%21 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %17, i32* %18, i32* %19, i32* %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %46
27: ; preds = %12
br label %28
28: ; preds = %38, %27
%29 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%30 = getelementptr inbounds i32, i32* %29, i64 1
%31 = load i32, i32* @stdin
%32 = call i32 @fread(i32* %30, i32 1, i32 4092, i32 %31)
%33 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
store i32 %32, i32* %33
%34 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %28
br label %45
38: ; preds = %28
%39 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%40 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%41 = call i32 @TEA_encrypt(i32* %39, i32 1024, i32* %40)
%42 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%43 = load i32, i32* @stdout
%44 = call i32 @fwrite(i32* %42, i32 4, i32 1024, i32 %43)
br label %28
45: ; preds = %37
br label %75
46: ; preds = %12
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %72
52: ; preds = %46
br label %53
53: ; preds = %70, %52
%54 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%55 = load i32, i32* @stdin
%56 = call i32 @fread(i32* %54, i32 4, i32 1024, i32 %55)
%57 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%58 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%59 = call i32 @TEA_decrypt(i32* %57, i32 1024, i32* %58)
%60 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%61 = getelementptr inbounds i32, i32* %60, i64 1
%62 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%63 = load i32, i32* %62
%64 = load i32, i32* @stdout
%65 = call i32 @fwrite(i32* %61, i32 1, i32 %63, i32 %64)
%66 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%67 = load i32, i32* %66
%68 = icmp slt i32 %67, 1023
br i1 %68, label %69, label %70
69: ; preds = %53
br label %71
70: ; preds = %53
br label %53
71: ; preds = %69
br label %74
72: ; preds = %46
%73 = call i32 (...) @Usage()
br label %74
74: ; preds = %72, %71
br label %75
75: ; preds = %74, %45
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"%08x%08x%08x%08x\00"
@.str.1 = [10 x i8] c"--encrypt\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [10 x i8] c"--decrypt\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i32]
%4 = alloca [1024 x i32]
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @Usage()
br label %8
8: ; preds = %6, %2
%9 = bitcast [4 x i32]* %3 to i8*
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%16 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %12, i32* %13, i32* %14, i32* %15)
%17 = bitcast [1024 x i32]* %4 to i8*
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %8
%23 = getelementptr inbounds [1024 x i32], [1024 x i32]* %4, i64 0, i64 0
%24 = getelementptr inbounds [1024 x i32], [1024 x i32]* %4, i64 0, i64 1
%25 = load i32, i32* @stdin
%26 = call i32 @fread(i32* %24, i32 1, i32 4092, i32 %25)
store i32 %26, i32* %23
%27 = icmp eq i32 %26, 0
br i1 %27, label %53, label %28
28: ; preds = %22, %28
%29 = call i32 @TEA_encrypt(i32* %23, i32 1024, i32* %12)
%30 = load i32, i32* @stdout
%31 = call i32 @fwrite(i32* %23, i32 4, i32 1024, i32 %30)
%32 = load i32, i32* @stdin
%33 = call i32 @fread(i32* %24, i32 1, i32 4092, i32 %32)
store i32 %33, i32* %23
%34 = icmp eq i32 %33, 0
br i1 %34, label %53, label %28
35: ; preds = %8
%36 = load i8*, i8** %18
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %35
%40 = getelementptr inbounds [1024 x i32], [1024 x i32]* %4, i64 0, i64 0
%41 = getelementptr inbounds [1024 x i32], [1024 x i32]* %4, i64 0, i64 1
br label %42
42: ; preds = %39, %42
%43 = load i32, i32* @stdin
%44 = call i32 @fread(i32* %40, i32 4, i32 1024, i32 %43)
%45 = call i32 @TEA_decrypt(i32* %40, i32 1024, i32* %12)
%46 = load i32, i32* %40
%47 = load i32, i32* @stdout
%48 = call i32 @fwrite(i32* %41, i32 1, i32 %46, i32 %47)
%49 = load i32, i32* %40
%50 = icmp slt i32 %49, 1023
br i1 %50, label %53, label %42
51: ; preds = %35
%52 = call i32 (...) @Usage()
br label %53
53: ; preds = %42, %28, %22, %51
ret i32 0
}