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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ slowprint(char *, int);
int encryption(char *input, char *foutput, int key) {
  int i, ch;
  char chaos;
  double x = key / 1000.0;
  FILE *fout;
  if ((fout = fopen(foutput, "w")) == 0) {
    slowprint("Cannot open output file.\n", 15);
    return 10;
  }
  for (i = 0; i < 100; i++) {
    x = x * 4 * (1 - x);
  }
  while ((ch = *input) != '\0') {
    x = x * 4 * (1 - x);
    chaos = (char)(x * 95);
    ch = ch ^ chaos;
    putc(ch, fout);
    input++;
  }
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<encryption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xea0(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11a4 <encryption+0x64>
lea    0xe94(%rip),%rdi
mov    $0xf,%esi
call   1050 <slowprint@plt>
movl   $0xa,-0x4(%rbp)
jmp    1278 <encryption+0x138>
movl   $0x0,-0x20(%rbp)
cmpl   $0x64,-0x20(%rbp)
jge    11e6 <encryption+0xa6>
movsd  0xe4b(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  0xe46(%rip),%xmm1
subsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ab <encryption+0x6b>
jmp    11eb <encryption+0xab>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     1268 <encryption+0x128>
movsd  -0x30(%rbp),%xmm2
movsd  0xdfd(%rip),%xmm1
movaps %xmm2,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdf6(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xde4(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,-0x25(%rbp)
mov    -0x24(%rbp),%eax
movsbl -0x25(%rbp),%ecx
xor    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1040 <putc@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11eb <encryption+0xab>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encryption>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xec9(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1250 <encryption+0x110>
mov    %rax,%r14
cvtsi2sd %ebp,%xmm1
divsd  0xe89(%rip),%xmm1
mov    $0x64,%eax
movsd  0xe84(%rip),%xmm2
movsd  0xe84(%rip),%xmm3
nopl   0x0(%rax)
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
add    $0xfffffffb,%eax
jne    1190 <encryption+0x50>
mov    (%rbx),%al
test   %al,%al
je     1244 <encryption+0x104>
add    $0x1,%rbx
nop
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
mulsd  0xe06(%rip),%xmm0
cvttsd2si %xmm0,%ecx
xor    %al,%cl
movsbl %cl,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
movsd  0xde5(%rip),%xmm3
movsd  0xdd5(%rip),%xmm2
movsd  0x8(%rsp),%xmm1
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11f0 <encryption+0xb0>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1266 <encryption+0x126>
lea    0xdcb(%rip),%rdi
mov    $0xf,%esi
call   1050 <slowprint@plt>
mov    $0xa,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [26 x i8] c"Cannot open output file.\0A\00"
define i32 @encryption(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca double
%12 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%13 = load i32, i32* %7
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, 1.000000e+03
store double %15, double* %11
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %12
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = call i32 @slowprint(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 15)
store i32 10, i32* %4
br label %61
21: ; preds = %3
store i32 0, i32* %8
br label %22
22: ; preds = %31, %21
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 100
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load double, double* %11
%27 = fmul double %26, 4.000000e+00
%28 = load double, double* %11
%29 = fsub double 1.000000e+00, %28
%30 = fmul double %27, %29
store double %30, double* %11
br label %31
31: ; preds = %25
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %22
34: ; preds = %22
br label %35
35: ; preds = %40, %34
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
store i32 %38, i32* %9
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %58
40: ; preds = %35
%41 = load double, double* %11
%42 = fmul double %41, 4.000000e+00
%43 = load double, double* %11
%44 = fsub double 1.000000e+00, %43
%45 = fmul double %42, %44
store double %45, double* %11
%46 = load double, double* %11
%47 = fmul double %46, 9.500000e+01
%48 = fptosi double %47 to i8
store i8 %48, i8* %10
%49 = load i32, i32* %9
%50 = load i8, i8* %10
%51 = sext i8 %50 to i32
%52 = xor i32 %49, %51
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = load i32*, i32** %12
%55 = call i32 @putc(i32 %53, i32* %54)
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %5
br label %35
58: ; preds = %35
%59 = load i32*, i32** %12
%60 = call i32 @fclose(i32* %59)
store i32 0, i32* %4
br label %61
61: ; preds = %58, %19
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [26 x i8] c"Cannot open output file.\0A\00"
define i32 @encryption(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @slowprint(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 15)
br label %51
8: ; preds = %3
%9 = sitofp i32 %2 to double
%10 = fdiv double %9, 1.000000e+03
br label %14
11: ; preds = %14
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 0
br i1 %13, label %49, label %34
14: ; preds = %14, %8
%15 = phi double [ %10, %8 ], [ %31, %14 ]
%16 = phi i32 [ 0, %8 ], [ %32, %14 ]
%17 = fmul double %15, 4.000000e+00
%18 = fsub double 1.000000e+00, %15
%19 = fmul double %17, %18
%20 = fmul double %19, 4.000000e+00
%21 = fsub double 1.000000e+00, %19
%22 = fmul double %20, %21
%23 = fmul double %22, 4.000000e+00
%24 = fsub double 1.000000e+00, %22
%25 = fmul double %23, %24
%26 = fmul double %25, 4.000000e+00
%27 = fsub double 1.000000e+00, %25
%28 = fmul double %26, %27
%29 = fmul double %28, 4.000000e+00
%30 = fsub double 1.000000e+00, %28
%31 = fmul double %29, %30
%32 = add nuw nsw i32 %16, 5
%33 = icmp eq i32 %32, 100
br i1 %33, label %11, label %14
34: ; preds = %11, %34
%35 = phi i8 [ %47, %34 ], [ %12, %11 ]
%36 = phi double [ %40, %34 ], [ %31, %11 ]
%37 = phi i8* [ %46, %34 ], [ %0, %11 ]
%38 = fmul double %36, 4.000000e+00
%39 = fsub double 1.000000e+00, %36
%40 = fmul double %38, %39
%41 = fmul double %40, 9.500000e+01
%42 = fptosi double %41 to i8
%43 = xor i8 %35, %42
%44 = sext i8 %43 to i32
%45 = tail call i32 @putc(i32 %44, i32* %4)
%46 = getelementptr inbounds i8, i8* %37, i64 1
%47 = load i8, i8* %46
%48 = icmp eq i8 %47, 0
br i1 %48, label %49, label %34
49: ; preds = %34, %11
%50 = tail call i32 @fclose(i32* %4)
br label %51
51: ; preds = %49, %6
%52 = phi i32 [ 10, %6 ], [ 0, %49 ]
ret i32 %52
}