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

/* Variables and functions */
int /*<<< orphan*/ decrypt(unsigned char *, size_t);
size_t encrypt(unsigned char **, char *, int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, size_t);
int main(int argc, char *argv[]) {
  size_t cipher1_len, cipher2_len;
  unsigned char *cipher1, *cipher2, *ccp;
  cipher1_len = encrypt(&cipher1, "AAAA", 4);
  if (NULL == cipher1 || 0 == cipher1_len)
    return 0x01;
  cipher2_len = encrypt(&cipher2, "BBBBBBBBBBadmin", 15);
  if (NULL == cipher2 || 16 > cipher2_len)
    return 0x01;
  ccp = malloc(cipher2_len * sizeof(char));
  if (NULL == ccp)
    return 0x01;
  memcpy(ccp, cipher1, 16);
  memcpy(ccp + 16, cipher2 + 16, 16);
  if (32 < cipher2_len)
    memset(ccp + 32, 0, cipher2_len - 32);
  decrypt(ccp, cipher2_len);
  free(cipher1);
  free(cipher2);
  free(ccp);
  return 0x00;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
lea    0xe7f(%rip),%rsi
mov    $0x4,%edx
call   1050 <encrypt@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
je     11a7 <main+0x47>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11b3 <main+0x53>
movl   $0x1,-0x4(%rbp)
jmp    129d <main+0x13d>
lea    -0x30(%rbp),%rdi
lea    0xe47(%rip),%rsi
mov    $0xf,%edx
call   1050 <encrypt@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
je     11e7 <main+0x87>
mov    $0x10,%eax
cmp    -0x20(%rbp),%rax
jbe    11f3 <main+0x93>
movl   $0x1,-0x4(%rbp)
jmp    129d <main+0x13d>
mov    -0x20(%rbp),%rdi
shl    $0x0,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    121c <main+0xbc>
movl   $0x1,-0x4(%rbp)
jmp    129d <main+0x13d>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    -0x38(%rbp),%rdi
add    $0x10,%rdi
mov    -0x30(%rbp),%rsi
add    $0x10,%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    $0x20,%eax
cmp    -0x20(%rbp),%rax
jae    126e <main+0x10e>
mov    -0x38(%rbp),%rdi
add    $0x20,%rdi
mov    -0x20(%rbp),%rdx
sub    $0x20,%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <decrypt@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe91(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1050 <encrypt@plt>
cmpq   $0x0,0x8(%rsp)
mov    $0x1,%ebp
je     123b <main+0xdb>
test   %rax,%rax
je     123b <main+0xdb>
lea    0xe66(%rip),%rsi
mov    %rsp,%rdi
mov    $0xf,%edx
call   1050 <encrypt@plt>
cmpq   $0x0,(%rsp)
je     123b <main+0xdb>
mov    %rax,%rbx
cmp    $0x10,%rax
jb     123b <main+0xdb>
mov    %rbx,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     123b <main+0xdb>
mov    %rax,%r14
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0x10,%edx
call   1070 <memcpy@plt>
lea    0x10(%r14),%rdi
mov    (%rsp),%rsi
add    $0x10,%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
cmp    $0x21,%rbx
jb     1213 <main+0xb3>
mov    %r14,%rdi
add    $0x20,%rdi
mov    %rbx,%rdx
add    $0xffffffffffffffe0,%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <decrypt@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    (%rsp),%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"AAAA\00"
@.str.1 = [16 x i8] c"BBBBBBBBBBadmin\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i64 @encrypt(i8** %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
store i64 %11, i64* %6
%12 = load i8*, i8** %8
%13 = icmp eq i8* null, %12
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i64, i64* %6
%16 = icmp eq i64 0, %15
br i1 %16, label %17, label %18
17: ; preds = %14, %2
store i32 1, i32* %3
br label %60
18: ; preds = %14
%19 = call i64 @encrypt(i8** %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 15)
store i64 %19, i64* %7
%20 = load i8*, i8** %9
%21 = icmp eq i8* null, %20
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i64, i64* %7
%24 = icmp ugt i64 16, %23
br i1 %24, label %25, label %26
25: ; preds = %22, %18
store i32 1, i32* %3
br label %60
26: ; preds = %22
%27 = load i64, i64* %7
%28 = mul i64 %27, 1
%29 = call i8* @malloc(i64 %28)
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = icmp eq i8* null, %30
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 1, i32* %3
br label %60
33: ; preds = %26
%34 = load i8*, i8** %10
%35 = load i8*, i8** %8
%36 = call i32 @memcpy(i8* %34, i8* %35, i32 16)
%37 = load i8*, i8** %10
%38 = getelementptr inbounds i8, i8* %37, i64 16
%39 = load i8*, i8** %9
%40 = getelementptr inbounds i8, i8* %39, i64 16
%41 = call i32 @memcpy(i8* %38, i8* %40, i32 16)
%42 = load i64, i64* %7
%43 = icmp ult i64 32, %42
br i1 %43, label %44, label %50
44: ; preds = %33
%45 = load i8*, i8** %10
%46 = getelementptr inbounds i8, i8* %45, i64 32
%47 = load i64, i64* %7
%48 = sub i64 %47, 32
%49 = call i32 @memset(i8* %46, i32 0, i64 %48)
br label %50
50: ; preds = %44, %33
%51 = load i8*, i8** %10
%52 = load i64, i64* %7
%53 = call i32 @decrypt(i8* %51, i64 %52)
%54 = load i8*, i8** %8
%55 = call i32 @free(i8* %54)
%56 = load i8*, i8** %9
%57 = call i32 @free(i8* %56)
%58 = load i8*, i8** %10
%59 = call i32 @free(i8* %58)
store i32 0, i32* %3
br label %60
60: ; preds = %50, %32, %25, %17
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [5 x i8] c"AAAA\00"
@.str.1 = [16 x i8] c"BBBBBBBBBBadmin\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = call i64 @encrypt(i8** %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
%10 = icmp eq i64 %7, 0
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %40, label %12
12: ; preds = %2
%13 = call i64 @encrypt(i8** %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 15)
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
%16 = icmp ult i64 %13, 16
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %40, label %18
18: ; preds = %12
%19 = call i8* @malloc(i64 %13)
%20 = icmp eq i8* %19, null
br i1 %20, label %40, label %21
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = call i32 @memcpy(i8* %19, i8* %22, i32 16)
%24 = getelementptr inbounds i8, i8* %19, i64 16
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 16
%27 = call i32 @memcpy(i8* %24, i8* %26, i32 16)
%28 = icmp ugt i64 %13, 32
br i1 %28, label %29, label %33
29: ; preds = %21
%30 = getelementptr inbounds i8, i8* %19, i64 32
%31 = add i64 %13, -32
%32 = call i32 @memset(i8* %30, i32 0, i64 %31)
br label %33
33: ; preds = %29, %21
%34 = call i32 @decrypt(i8* %19, i64 %13)
%35 = load i8*, i8** %3
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %4
%38 = call i32 @free(i8* %37)
%39 = call i32 @free(i8* %19)
br label %40
40: ; preds = %18, %12, %2, %33
%41 = phi i32 [ 0, %33 ], [ 1, %2 ], [ 1, %12 ], [ 1, %18 ]
ret i32 %41
}