#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*/ BF_KEY;

/* Variables and functions */
int /*<<< orphan*/ BF_DECRYPT;
int /*<<< orphan*/ BF_ENCRYPT;
int /*<<< orphan*/ BF_ecb_encrypt(unsigned char *, unsigned char *,
                                  int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BF_set_key(int /*<<< orphan*/ *, int, unsigned char const *);
unsigned char *bf_str_decrypt(unsigned char *);
unsigned char *bf_str_encrypt(char *);
void *calloc(int, int);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ printf(char *, unsigned char *);
int /*<<< orphan*/ puts(char *);
int main() {
  unsigned char *in = (unsigned char *)"TestData";
  unsigned char *out = calloc(1024, sizeof(unsigned char *));
  unsigned char *out2 = calloc(1024, sizeof(unsigned char *));
  unsigned char *out3 = calloc(1024, sizeof(unsigned char *));
  BF_KEY *key = calloc(256, 256);
  BF_set_key(key, 256, (const unsigned char *)"TestKey");
  BF_ecb_encrypt(in, out, key, BF_ENCRYPT);
  printf("%s\n", out);
  BF_ecb_encrypt(out, out2, key, BF_DECRYPT);
  printf("%s\n", out2);
  unsigned char *out4 = bf_str_encrypt("seu madruga na vila");
  printf("result %s \n", out4);
  puts("OK!");
  unsigned char *out5 = bf_str_decrypt(out4);
  printf("result decrypt %s \n", out5);
  if (out)
    free(out);
  if (out2)
    free(out2);
  if (out4)
    free(out4);
  if (out5)
    free(out5);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x400,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x400,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x400,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x100,%esi
mov    %esi,%edi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x100,%esi
lea    0xe16(%rip),%rdx
call   1070 <BF_set_key@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    0x2dcd(%rip),%rax
mov    (%rax),%ecx
call   1050 <BF_ecb_encrypt@plt>
mov    -0x18(%rbp),%rsi
lea    0xdf4(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    0x2db3(%rip),%rax
mov    (%rax),%ecx
call   1050 <BF_ecb_encrypt@plt>
mov    -0x20(%rbp),%rsi
lea    0xdca(%rip),%rdi
call   1060 <printf@plt>
lea    0xdc2(%rip),%rdi
call   10a0 <bf_str_encrypt@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xdc2(%rip),%rdi
call   1060 <printf@plt>
lea    0xdc2(%rip),%rdi
call   1040 <puts@plt>
mov    -0x38(%rbp),%rdi
call   1090 <bf_str_decrypt@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
lea    0xda9(%rip),%rdi
call   1060 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     12a9 <main+0x129>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     12bd <main+0x13d>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     12d1 <main+0x151>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     12e5 <main+0x165>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x400,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r15
mov    $0x400,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r14
mov    $0x100,%edi
mov    $0x100,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
lea    0xe44(%rip),%rdx
mov    %rax,%rdi
mov    $0x100,%esi
call   1070 <BF_set_key@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%ecx
lea    0xe1e(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <BF_ecb_encrypt@plt>
lea    0xe1d(%rip),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <BF_ecb_encrypt@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
lea    0xded(%rip),%rdi
call   10a0 <bf_str_encrypt@plt>
mov    %rax,%rbx
lea    0xdf2(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
lea    0xdef(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1090 <bf_str_decrypt@plt>
mov    %rax,%r12
lea    0xddc(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
test   %r15,%r15
je     1272 <main+0xf2>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     127f <main+0xff>
mov    %r14,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     128c <main+0x10c>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r12,%r12
je     1299 <main+0x119>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"TestData\00"
@.str.1 = [8 x i8] c"TestKey\00"
@BF_ENCRYPT = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@BF_DECRYPT = global i32 0
@.str.3 = [20 x i8] c"seu madruga na vila\00"
@.str.4 = [12 x i8] c"result %s \0A\00"
@.str.5 = [4 x i8] c"OK!\00"
@.str.6 = [20 x i8] c"result decrypt %s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
%9 = call i8* @calloc(i32 1024, i32 8)
store i8* %9, i8** %3
%10 = call i8* @calloc(i32 1024, i32 8)
store i8* %10, i8** %4
%11 = call i8* @calloc(i32 1024, i32 8)
store i8* %11, i8** %5
%12 = call i8* @calloc(i32 256, i32 256)
%13 = bitcast i8* %12 to i32*
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = call i32 @BF_set_key(i32* %14, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%16 = load i8*, i8** %2
%17 = load i8*, i8** %3
%18 = load i32*, i32** %6
%19 = load i32, i32* @BF_ENCRYPT
%20 = call i32 @BF_ecb_encrypt(i8* %16, i8* %17, i32* %18, i32 %19)
%21 = load i8*, i8** %3
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %3
%24 = load i8*, i8** %4
%25 = load i32*, i32** %6
%26 = load i32, i32* @BF_DECRYPT
%27 = call i32 @BF_ecb_encrypt(i8* %23, i8* %24, i32* %25, i32 %26)
%28 = load i8*, i8** %4
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i8* @bf_str_encrypt(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%34 = load i8*, i8** %7
%35 = call i8* @bf_str_decrypt(i8* %34)
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %3
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %43
40: ; preds = %0
%41 = load i8*, i8** %3
%42 = call i32 @free(i8* %41)
br label %43
43: ; preds = %40, %0
%44 = load i8*, i8** %4
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i8*, i8** %4
%48 = call i32 @free(i8* %47)
br label %49
49: ; preds = %46, %43
%50 = load i8*, i8** %7
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i8*, i8** %7
%54 = call i32 @free(i8* %53)
br label %55
55: ; preds = %52, %49
%56 = load i8*, i8** %8
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i8*, i8** %8
%60 = call i32 @free(i8* %59)
br label %61
61: ; preds = %58, %55
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"TestData\00"
@.str.1 = [8 x i8] c"TestKey\00"
@BF_ENCRYPT = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@BF_DECRYPT = global i32 0
@.str.3 = [20 x i8] c"seu madruga na vila\00"
@.str.4 = [12 x i8] c"result %s \0A\00"
@.str.5 = [4 x i8] c"OK!\00"
@.str.6 = [20 x i8] c"result decrypt %s \0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(8192) i8* @calloc(i32 1024, i32 8)
%2 = tail call dereferenceable_or_null(8192) i8* @calloc(i32 1024, i32 8)
%3 = tail call dereferenceable_or_null(65536) i8* @calloc(i32 256, i32 256)
%4 = bitcast i8* %3 to i32*
%5 = tail call i32 @BF_set_key(i32* %4, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @BF_ENCRYPT
%7 = tail call i32 @BF_ecb_encrypt(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %1, i32* %4, i32 %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%9 = load i32, i32* @BF_DECRYPT
%10 = tail call i32 @BF_ecb_encrypt(i8* %1, i8* %2, i32* %4, i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%12 = tail call i8* @bf_str_encrypt(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%15 = tail call i8* @bf_str_decrypt(i8* %12)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %15)
%17 = icmp eq i8* %1, null
br i1 %17, label %20, label %18
18: ; preds = %0
%19 = tail call i32 @free(i8* %1)
br label %20
20: ; preds = %18, %0
%21 = icmp eq i8* %2, null
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = tail call i32 @free(i8* %2)
br label %24
24: ; preds = %22, %20
%25 = icmp eq i8* %12, null
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = tail call i32 @free(i8* %12)
br label %28
28: ; preds = %26, %24
%29 = icmp eq i8* %15, null
br i1 %29, label %32, label %30
30: ; preds = %28
%31 = tail call i32 @free(i8* %15)
br label %32
32: ; preds = %30, %28
ret i32 0
}