#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*/ OS_BF_Str(char *, char *, char *, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char **argv) {
  int i;
  char output[1024];
  char output2[1024];
  memset(output, '\0', 1024);
  memset(output2, '\0', 1024);
  if (argc < 3) {
    printf("%s: string key\n", argv[0]);
    exit(1);
  }
  if ((strlen(argv[1]) > 1020) || (strlen(argv[2]) > 512)) {
    printf("%s: size err\n", argv[0]);
    exit(1);
  }
  OS_BF_Str(argv[1], output, argv[2], strlen(argv[1]), 1);
  OS_BF_Str(output, output2, argv[2], strlen(argv[1]), 0);
  printf("finished.\n");
  printf("input: '%s'\n", argv[1]);
  printf("crpt: ");
  for (i = 0; i <= strlen(argv[1]); i++) {
    printf("%d", output[i]);
  }
  printf("\n");
  printf("output2: '%s'\n", output2);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
jge    11b8 <main+0x68>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
cmp    $0x3fc,%eax
jg     11e8 <main+0x98>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
cmp    $0x200,%eax
jle    1207 <main+0xb7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x850(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x848(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x840(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x850(%rbp),%rdi
mov    -0x848(%rbp),%rsi
mov    -0x840(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%r8d
call   1060 <OS_BF_Str@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x828(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rsi
mov    -0x828(%rbp),%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1060 <OS_BF_Str@plt>
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x854(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x854(%rbp),%eax
cmp    %ecx,%eax
jg     1340 <main+0x1f0>
movslq -0x14(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%esi
ff
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12f2 <main+0x1a2>
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x820(%rbp),%rsi
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x400(%rsp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
cmp    $0x2,%ebx
jle    12ce <main+0x15e>
mov    0x8(%r14),%rdi
call   1050 <strlen@plt>
cmp    $0x3fc,%eax
jg     12c2 <main+0x152>
mov    0x10(%r14),%rdi
call   1050 <strlen@plt>
cmp    $0x201,%eax
jge    12c2 <main+0x152>
mov    0x8(%r14),%rbx
mov    0x10(%r14),%r15
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x400(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
mov    $0x1,%r8d
call   1080 <OS_BF_Str@plt>
mov    0x8(%r14),%rdi
mov    0x10(%r14),%rbx
call   1050 <strlen@plt>
mov    %rsp,%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1080 <OS_BF_Str@plt>
lea    0xe18(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%r14),%rsi
lea    0xde2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xde1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%r14),%rdi
call   1050 <strlen@plt>
test   %eax,%eax
js     1296 <main+0x126>
mov    $0xffffffffffffffff,%rbx
lea    0xdc6(%rip),%r15
nopl   0x0(%rax)
movsbl 0x401(%rsp,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%r14),%rdi
call   1050 <strlen@plt>
cltq
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1270 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd8e(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%r14),%rsi
lea    0xd44(%rip),%rdi
jmp    12d8 <main+0x168>
mov    (%r14),%rsi
lea    0xd28(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"%s: string key\0A\00"
@.str.1 = [14 x i8] c"%s: size err\0A\00"
@.str.2 = [11 x i8] c"finished.\0A\00"
@.str.3 = [13 x i8] c"input: '%s'\0A\00"
@.str.4 = [7 x i8] c"crpt: \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [15 x i8] c"output2: '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i8 signext 0, i32 1024)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i8 signext 0, i32 1024)
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strlen(i8* %24)
%26 = icmp sgt i32 %25, 1020
br i1 %26, label %33, label %27
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = icmp sgt i32 %31, 512
br i1 %32, label %33, label %39
33: ; preds = %27, %21
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %27
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @OS_BF_Str(i8* %42, i8* %43, i8* %46, i32 %50, i32 1)
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32 @strlen(i8* %59)
%61 = call i32 @OS_BF_Str(i8* %52, i8* %53, i8* %56, i32 %60, i32 0)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %65)
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %68
68: ; preds = %82, %39
%69 = load i32, i32* %6
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = load i8*, i8** %71
%73 = call i32 @strlen(i8* %72)
%74 = icmp sle i32 %69, %73
br i1 %74, label %75, label %85
75: ; preds = %68
%76 = load i32, i32* %6
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %75
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %68
85: ; preds = %68
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %87)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"%s: string key\0A\00"
@.str.1 = [14 x i8] c"%s: size err\0A\00"
@.str.3 = [13 x i8] c"input: '%s'\0A\00"
@.str.4 = [7 x i8] c"crpt: \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.7 = [15 x i8] c"output2: '%s'\0A\00"
@str = [10 x i8] c"finished.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %5, i8 signext 0, i32 1024)
%8 = call i32 @memset(i8* %6, i8 signext 0, i32 1024)
%9 = icmp slt i32 %0, 3
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
%18 = icmp sgt i32 %17, 1020
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @strlen(i8* %21)
%23 = icmp sgt i32 %22, 512
br i1 %23, label %24, label %28
24: ; preds = %19, %14
%25 = load i8*, i8** %1
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = load i8*, i8** %15
%30 = load i8*, i8** %20
%31 = call i32 @strlen(i8* %29)
%32 = call i32 @OS_BF_Str(i8* %29, i8* %5, i8* %30, i32 %31, i32 1)
%33 = load i8*, i8** %20
%34 = load i8*, i8** %15
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @OS_BF_Str(i8* %5, i8* %6, i8* %33, i32 %35, i32 0)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%38 = load i8*, i8** %15
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%41 = load i8*, i8** %15
%42 = call i32 @strlen(i8* %41)
%43 = icmp slt i32 %42, 0
br i1 %43, label %55, label %44
44: ; preds = %28, %44
%45 = phi i64 [ %50, %44 ], [ 0, %28 ]
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = add nuw nsw i64 %45, 1
%51 = load i8*, i8** %15
%52 = call i32 @strlen(i8* %51)
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %45, %53
br i1 %54, label %44, label %55
55: ; preds = %44, %28
%56 = call i32 @putchar(i32 10)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %6)
ret i32 0
}