#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_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*/ free(unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(unsigned char *, unsigned char *);
int /*<<< orphan*/ strlen(unsigned char *);
unsigned char *bf_str_decrypt(unsigned char *str) {
  if (!strlen(str))
    return ".";
  unsigned char *ptr = str;
  unsigned char *decrypt = (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(decrypt, 512);
  while (*ptr != '\0' && counter != 511) {
    *(tmp + jmp) = *ptr;
    if (jmp == 7) {
      BF_ecb_encrypt(tmp, out, key, BF_DECRYPT);
      strcat(decrypt, out);
      bzero(out, 9);
      bzero(tmp, 9);
      jmp = -1;
    }
    ptr++;
    jmp++;
    counter++;
  }
  if (jmp > 0 && jmp < 8) {
    BF_ecb_encrypt(tmp, out, key, BF_DECRYPT);
    strcat(decrypt, out);
  }
  bzero(out, 9);
  bzero(tmp, 9);
  if (out)
    free(out);
  if (tmp)
    free(tmp);
  return decrypt;
}


x86 assembly (clang, -O0):
<bf_str_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    11ae <bf_str_decrypt+0x2e>
lea    0xe5b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1366 <bf_str_decrypt+0x1e6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x200,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x9,%edi
call   1080 <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    0xdfd(%rip),%rdx
call   1060 <BF_set_key@plt>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x200,%esi
call   1090 <bzero@plt>
mov    -0x18(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x41(%rbp)
je     1248 <bf_str_decrypt+0xc8>
cmpl   $0x1ff,-0x40(%rbp)
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1258 <bf_str_decrypt+0xd8>
jmp    12df <bf_str_decrypt+0x15f>
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    12bc <bf_str_decrypt+0x13c>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    0x2d63(%rip),%rax
mov    (%rax),%ecx
call   1040 <BF_ecb_encrypt@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    $0x9,%esi
call   1090 <bzero@plt>
mov    -0x28(%rbp),%rdi
mov    $0x9,%esi
call   1090 <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    1226 <bf_str_decrypt+0xa6>
cmpl   $0x0,-0x3c(%rbp)
jbe    131a <bf_str_decrypt+0x19a>
cmpl   $0x8,-0x3c(%rbp)
jae    131a <bf_str_decrypt+0x19a>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    0x2ce2(%rip),%rax
mov    (%rax),%ecx
call   1040 <BF_ecb_encrypt@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    $0x9,%esi
call   1090 <bzero@plt>
mov    -0x28(%rbp),%rdi
mov    $0x9,%esi
call   1090 <bzero@plt>
cmpq   $0x0,-0x30(%rbp)
je     134a <bf_str_decrypt+0x1ca>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
je     135e <bf_str_decrypt+0x1de>
mov    -0x28(%rbp),%rdi
call   1030 <free@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_decrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1050 <strlen@plt>
test   %eax,%eax
je     12d5 <bf_str_decrypt+0x155>
mov    $0x200,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0x9,%edi
call   1080 <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,%r13
lea    0xe22(%rip),%rdx
mov    %rax,%rdi
mov    $0x100,%esi
call   1060 <BF_set_key@plt>
mov    %r14,%rdi
mov    $0x200,%esi
call   1090 <bzero@plt>
mov    (%r12),%al
test   %al,%al
je     129f <bf_str_decrypt+0x11f>
xor    %ecx,%ecx
mov    $0x1,%ebp
nopl   (%rax)
mov    %ecx,%edx
mov    %al,(%rbx,%rdx,1)
mov    %ecx,%edx
cmp    $0x7,%ecx
jne    125d <bf_str_decrypt+0xdd>
mov    0x2dc5(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <BF_ecb_encrypt@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
mov    %r15,%rdi
mov    $0x9,%esi
call   1090 <bzero@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1090 <bzero@plt>
mov    $0xffffffff,%edx
movzbl (%r12,%rbp,1),%eax
test   %al,%al
je     1278 <bf_str_decrypt+0xf8>
lea    0x1(%rdx),%ecx
lea    0x1(%rbp),%rsi
cmp    $0x1ff,%ebp
mov    %rsi,%rbp
jne    1210 <bf_str_decrypt+0x90>
cmp    $0x6,%edx
ja     129f <bf_str_decrypt+0x11f>
mov    0x2d64(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <BF_ecb_encrypt@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
mov    %r15,%rdi
mov    $0x9,%esi
call   1090 <bzero@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1090 <bzero@plt>
test   %r15,%r15
je     12c6 <bf_str_decrypt+0x146>
mov    %r15,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     12dc <bf_str_decrypt+0x15c>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    12dc <bf_str_decrypt+0x15c>
lea    0xd24(%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_DECRYPT = global i32 0
define i8* @bf_str_decrypt(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 %100
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, 511
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_DECRYPT
%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 @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 i32, i32* %9
%69 = icmp ugt i32 %68, 0
br i1 %69, label %70, label %82
70: ; preds = %67
%71 = load i32, i32* %9
%72 = icmp ult i32 %71, 8
br i1 %72, label %73, label %82
73: ; preds = %70
%74 = load i8*, i8** %6
%75 = load i8*, i8** %7
%76 = load i32*, i32** %8
%77 = load i32, i32* @BF_DECRYPT
%78 = call i32 @BF_ecb_encrypt(i8* %74, i8* %75, i32* %76, i32 %77)
%79 = load i8*, i8** %5
%80 = load i8*, i8** %7
%81 = call i32 @strcat(i8* %79, i8* %80)
br label %82
82: ; preds = %73, %70, %67
%83 = load i8*, i8** %7
%84 = call i32 @bzero(i8* %83, i32 9)
%85 = load i8*, i8** %6
%86 = call i32 @bzero(i8* %85, i32 9)
%87 = load i8*, i8** %7
%88 = icmp ne i8* %87, null
br i1 %88, label %89, label %92
89: ; preds = %82
%90 = load i8*, i8** %7
%91 = call i32 @free(i8* %90)
br label %92
92: ; preds = %89, %82
%93 = load i8*, i8** %6
%94 = icmp ne i8* %93, null
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = load i8*, i8** %6
%97 = call i32 @free(i8* %96)
br label %98
98: ; preds = %95, %92
%99 = load i8*, i8** %5
store i8* %99, i8** %2
br label %100
100: ; preds = %98, %14
%101 = load i8*, i8** %2
ret i8* %101
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [8 x i8] c"TestKey\00"
@BF_DECRYPT = global i32 0
define i8* @bf_str_decrypt(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %55, 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 %45, 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_DECRYPT
%26 = tail call i32 @BF_ecb_encrypt(i8* %8, i8* %9, i32* %11, i32 %25)
%27 = tail call i32 @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, 511
%38 = select i1 %36, i1 %37, i1 false
br i1 %38, label %16, label %39
39: ; preds = %30
%40 = icmp ult i32 %31, 7
br i1 %40, label %41, label %45
41: ; preds = %39
%42 = load i32, i32* @BF_DECRYPT
%43 = tail call i32 @BF_ecb_encrypt(i8* %8, i8* %9, i32* %11, i32 %42)
%44 = tail call i32 @strcat(i8* %6, i8* %9)
br label %45
45: ; preds = %4, %41, %39
%46 = tail call i32 @bzero(i8* %9, i32 9)
%47 = tail call i32 @bzero(i8* %8, i32 9)
%48 = icmp eq i8* %9, null
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = tail call i32 @free(i8* %9)
br label %51
51: ; preds = %49, %45
%52 = icmp eq i64 %7, 0
br i1 %52, label %55, label %53
53: ; preds = %51
%54 = tail call i32 @free(i8* %8)
br label %55
55: ; preds = %51, %53, %1
%56 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ], [ %6, %53 ], [ %6, %51 ]
ret i8* %56
}