#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_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 *);
int /*<<< orphan*/ bzero(unsigned char *, int);
void *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned char *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(unsigned char *, ...);
int strlen(unsigned char *);
unsigned char *bf_str_encrypt(unsigned char *str) {
  if (!strlen(str))
    return ".";
  unsigned char *ptr = str;
  unsigned char *encrypt = (unsigned char *)malloc(sizeof(char) * 512);
  unsigned char *tmp = (unsigned char *)malloc(sizeof(char) * 9);
  unsigned char *out = calloc(9, sizeof(unsigned char *));
  BF_KEY *key = calloc(9, 9);
  BF_set_key(key, 256, (const unsigned char *)"TestKey");
  unsigned int jmp = 0, counter = 0;
  bzero(encrypt, 512);
  while (*ptr != '\0' && counter != 512) {
    *(tmp + jmp) = *ptr;
    if (jmp == 7) {
      BF_ecb_encrypt(tmp, out, key, BF_ENCRYPT);
      strcat(encrypt, out);
      bzero(out, 9);
      bzero(tmp, 9);
      jmp = -1;
    }
    ptr++;
    jmp++;
    counter++;
  }
  if (strlen(tmp) <= 8) {
    bzero(out, 9);
    while (strlen(tmp) < 7)
      strcat(tmp, ".");
    BF_ecb_encrypt(tmp, out, key, BF_ENCRYPT);
    strcat(encrypt, out);
  }
  bzero(out, 9);
  bzero(tmp, 9);
  if (out)
    free(out);
  if (tmp)
    free(tmp);
  fprintf(stdout, "Result %s\n", encrypt);
  return encrypt;
}


x86 assembly (clang, -O0):
<bf_str_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    11be <bf_str_encrypt+0x2e>
lea    0xe4b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13c8 <bf_str_encrypt+0x238>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x200,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x9,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x9,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x9,%esi
mov    %esi,%edi
call   1070 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x100,%esi
lea    0xded(%rip),%rdx
call   1060 <BF_set_key@plt>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x200,%esi
call   10a0 <bzero@plt>
mov    -0x18(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x41(%rbp)
je     1258 <bf_str_encrypt+0xc8>
cmpl   $0x200,-0x40(%rbp)
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1268 <bf_str_encrypt+0xd8>
jmp    12f1 <bf_str_encrypt+0x161>
mov    -0x18(%rbp),%rax
mov    (%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x7,-0x3c(%rbp)
jne    12ce <bf_str_encrypt+0x13e>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    0x2d43(%rip),%rax
mov    (%rax),%ecx
call   1040 <BF_ecb_encrypt@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x0,%al
call   10b0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
mov    -0x28(%rbp),%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1236 <bf_str_encrypt+0xa6>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x8,%eax
jg     1363 <bf_str_encrypt+0x1d3>
mov    -0x30(%rbp),%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x7,%eax
jge    133a <bf_str_encrypt+0x1aa>
mov    -0x28(%rbp),%rdi
lea    0xcd2(%rip),%rsi
mov    $0x0,%al
call   10b0 <strcat@plt>
jmp    1311 <bf_str_encrypt+0x181>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    0x2c8b(%rip),%rax
mov    (%rax),%ecx
call   1040 <BF_ecb_encrypt@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x0,%al
call   10b0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
mov    -0x28(%rbp),%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
cmpq   $0x0,-0x30(%rbp)
je     1393 <bf_str_encrypt+0x203>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
je     13a7 <bf_str_encrypt+0x217>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xc4f(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bf_str_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
call   1050 <strlen@plt>
test   %eax,%eax
je     134c <bf_str_encrypt+0x1bc>
mov    $0x200,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    $0x9,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    $0x9,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
mov    $0x9,%edi
mov    $0x9,%esi
call   1070 <calloc@plt>
mov    %rax,%r12
lea    0xe12(%rip),%rdx
mov    %rax,%rdi
mov    $0x100,%esi
call   1060 <BF_set_key@plt>
mov    %r14,%rdi
mov    $0x200,%esi
call   10a0 <bzero@plt>
mov    0x0(%r13),%al
test   %al,%al
je     1289 <bf_str_encrypt+0xf9>
mov    $0x1,%ebp
xor    %ecx,%ecx
nopl   0x0(%rax)
mov    %ecx,%edx
mov    %al,(%rbx,%rdx,1)
cmp    $0x7,%ecx
jne    126d <bf_str_encrypt+0xdd>
mov    0x2da7(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <BF_ecb_encrypt@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10b0 <strcat@plt>
mov    %r15,%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
mov    $0xffffffff,%ecx
movzbl 0x0(%r13,%rbp,1),%eax
test   %al,%al
je     1289 <bf_str_encrypt+0xf9>
add    $0x1,%ecx
lea    0x1(%rbp),%rdx
cmp    $0x200,%ebp
mov    %rdx,%rbp
jne    1220 <bf_str_encrypt+0x90>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x8,%eax
jg     12fe <bf_str_encrypt+0x16e>
mov    %r15,%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x6,%eax
jg     12da <bf_str_encrypt+0x14a>
lea    0xd49(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   10b0 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x7,%eax
jl     12c0 <bf_str_encrypt+0x130>
mov    0x2cf7(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <BF_ecb_encrypt@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10b0 <strcat@plt>
mov    %r15,%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   10a0 <bzero@plt>
test   %r15,%r15
je     1325 <bf_str_encrypt+0x195>
mov    %r15,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     1332 <bf_str_encrypt+0x1a2>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    0xcc8(%rip),%rsi
mov    %r14,%rdx
call   1080 <fprintf@plt>
jmp    1353 <bf_str_encrypt+0x1c3>
lea    0xcad(%rip),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [8 x i8] c"TestKey\00"
@BF_ENCRYPT = global i32 0
@stdout = global i32 0
@.str.2 = [11 x i8] c"Result %s\0A\00"
define i8* @bf_str_encrypt(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
br label %111
15: ; preds = %1
%16 = load i8*, i8** %3
store i8* %16, i8** %4
%17 = call i64 @malloc(i32 512)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
%19 = call i64 @malloc(i32 9)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %6
%21 = call i8* @calloc(i32 9, i32 8)
store i8* %21, i8** %7
%22 = call i8* @calloc(i32 9, i32 9)
%23 = bitcast i8* %22 to i32*
store i32* %23, i32** %8
%24 = load i32*, i32** %8
%25 = call i32 @BF_set_key(i32* %24, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %9
store i32 0, i32* %10
%26 = load i8*, i8** %5
%27 = call i32 @bzero(i8* %26, i32 512)
br label %28
28: ; preds = %60, %15
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* %10
%35 = icmp ne i32 %34, 512
br label %36
36: ; preds = %33, %28
%37 = phi i1 [ false, %28 ], [ %35, %33 ]
br i1 %37, label %38, label %67
38: ; preds = %36
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = load i8*, i8** %6
%42 = load i32, i32* %9
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %40, i8* %44
%45 = load i32, i32* %9
%46 = icmp eq i32 %45, 7
br i1 %46, label %47, label %60
47: ; preds = %38
%48 = load i8*, i8** %6
%49 = load i8*, i8** %7
%50 = load i32*, i32** %8
%51 = load i32, i32* @BF_ENCRYPT
%52 = call i32 @BF_ecb_encrypt(i8* %48, i8* %49, i32* %50, i32 %51)
%53 = load i8*, i8** %5
%54 = load i8*, i8** %7
%55 = call i32 (i8*, ...) @strcat(i8* %53, i8* %54)
%56 = load i8*, i8** %7
%57 = call i32 @bzero(i8* %56, i32 9)
%58 = load i8*, i8** %6
%59 = call i32 @bzero(i8* %58, i32 9)
store i32 -1, i32* %9
br label %60
60: ; preds = %47, %38
%61 = load i8*, i8** %4
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %4
%63 = load i32, i32* %9
%64 = add i32 %63, 1
store i32 %64, i32* %9
%65 = load i32, i32* %10
%66 = add i32 %65, 1
store i32 %66, i32* %10
br label %28
67: ; preds = %36
%68 = load i8*, i8** %6
%69 = call i32 @strlen(i8* %68)
%70 = icmp sle i32 %69, 8
br i1 %70, label %71, label %90
71: ; preds = %67
%72 = load i8*, i8** %7
%73 = call i32 @bzero(i8* %72, i32 9)
br label %74
74: ; preds = %78, %71
%75 = load i8*, i8** %6
%76 = call i32 @strlen(i8* %75)
%77 = icmp slt i32 %76, 7
br i1 %77, label %78, label %81
78: ; preds = %74
%79 = load i8*, i8** %6
%80 = call i32 (i8*, ...) @strcat(i8* %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %74
81: ; preds = %74
%82 = load i8*, i8** %6
%83 = load i8*, i8** %7
%84 = load i32*, i32** %8
%85 = load i32, i32* @BF_ENCRYPT
%86 = call i32 @BF_ecb_encrypt(i8* %82, i8* %83, i32* %84, i32 %85)
%87 = load i8*, i8** %5
%88 = load i8*, i8** %7
%89 = call i32 (i8*, ...) @strcat(i8* %87, i8* %88)
br label %90
90: ; preds = %81, %67
%91 = load i8*, i8** %7
%92 = call i32 @bzero(i8* %91, i32 9)
%93 = load i8*, i8** %6
%94 = call i32 @bzero(i8* %93, i32 9)
%95 = load i8*, i8** %7
%96 = icmp ne i8* %95, null
br i1 %96, label %97, label %100
97: ; preds = %90
%98 = load i8*, i8** %7
%99 = call i32 @free(i8* %98)
br label %100
100: ; preds = %97, %90
%101 = load i8*, i8** %6
%102 = icmp ne i8* %101, null
br i1 %102, label %103, label %106
103: ; preds = %100
%104 = load i8*, i8** %6
%105 = call i32 @free(i8* %104)
br label %106
106: ; preds = %103, %100
%107 = load i32, i32* @stdout
%108 = load i8*, i8** %5
%109 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %108)
%110 = load i8*, i8** %5
store i8* %110, i8** %2
br label %111
111: ; preds = %106, %14
%112 = load i8*, i8** %2
ret i8* %112
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [8 x i8] c"TestKey\00"
@BF_ENCRYPT = global i32 0
@stdout = global i32 0
@.str.2 = [11 x i8] c"Result %s\0A\00"
define i8* @bf_str_encrypt(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %67, label %4
4: ; preds = %1
%5 = tail call i64 @malloc(i32 512)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i64 @malloc(i32 9)
%8 = inttoptr i64 %7 to i8*
%9 = tail call dereferenceable_or_null(72) i8* @calloc(i32 9, i32 8)
%10 = tail call dereferenceable_or_null(81) i8* @calloc(i32 9, i32 9)
%11 = bitcast i8* %10 to i32*
%12 = tail call i32 @BF_set_key(i32* %11, i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @bzero(i8* %6, i32 512)
%14 = load i8, i8* %0
%15 = icmp eq i8 %14, 0
br i1 %15, label %39, label %16
16: ; preds = %4, %30
%17 = phi i8 [ %35, %30 ], [ %14, %4 ]
%18 = phi i32 [ %34, %30 ], [ 0, %4 ]
%19 = phi i32 [ %33, %30 ], [ 0, %4 ]
%20 = phi i8* [ %32, %30 ], [ %0, %4 ]
%21 = zext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %8, i64 %21
store i8 %17, i8* %22
%23 = icmp eq i32 %19, 7
br i1 %23, label %24, label %30
24: ; preds = %16
%25 = load i32, i32* @BF_ENCRYPT
%26 = tail call i32 @BF_ecb_encrypt(i8* %8, i8* %9, i32* %11, i32 %25)
%27 = tail call i32 (i8*, ...) @strcat(i8* %6, i8* %9)
%28 = tail call i32 @bzero(i8* %9, i32 9)
%29 = tail call i32 @bzero(i8* %8, i32 9)
br label %30
30: ; preds = %24, %16
%31 = phi i32 [ -1, %24 ], [ %19, %16 ]
%32 = getelementptr inbounds i8, i8* %20, i64 1
%33 = add i32 %31, 1
%34 = add nuw nsw i32 %18, 1
%35 = load i8, i8* %32
%36 = icmp ne i8 %35, 0
%37 = icmp ne i32 %34, 512
%38 = select i1 %36, i1 %37, i1 false
br i1 %38, label %16, label %39
39: ; preds = %30, %4
%40 = tail call i32 @strlen(i8* %8)
%41 = icmp slt i32 %40, 9
br i1 %41, label %42, label %54
42: ; preds = %39
%43 = tail call i32 @bzero(i8* %9, i32 9)
%44 = tail call i32 @strlen(i8* %8)
%45 = icmp slt i32 %44, 7
br i1 %45, label %46, label %50
46: ; preds = %42, %46
%47 = tail call i32 (i8*, ...) @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%48 = tail call i32 @strlen(i8* %8)
%49 = icmp slt i32 %48, 7
br i1 %49, label %46, label %50
50: ; preds = %46, %42
%51 = load i32, i32* @BF_ENCRYPT
%52 = tail call i32 @BF_ecb_encrypt(i8* %8, i8* %9, i32* %11, i32 %51)
%53 = tail call i32 (i8*, ...) @strcat(i8* %6, i8* %9)
br label %54
54: ; preds = %50, %39
%55 = tail call i32 @bzero(i8* %9, i32 9)
%56 = tail call i32 @bzero(i8* %8, i32 9)
%57 = icmp eq i8* %9, null
br i1 %57, label %60, label %58
58: ; preds = %54
%59 = tail call i32 @free(i8* %9)
br label %60
60: ; preds = %58, %54
%61 = icmp eq i64 %7, 0
br i1 %61, label %64, label %62
62: ; preds = %60
%63 = tail call i32 @free(i8* %8)
br label %64
64: ; preds = %62, %60
%65 = load i32, i32* @stdout
%66 = tail call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %67
67: ; preds = %1, %64
%68 = phi i8* [ %6, %64 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %68
}