#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int strlen(char *);
void decrypt2(char *crypt_path, char *decrypt_path, char *password) {
  FILE *normal_fp = fopen(crypt_path, "rb");
  FILE *crypt_fp = fopen(decrypt_path, "wb");
  int ch;
  int i = 0;
  int pwd_len = strlen(password);
  while ((ch = fgetc(normal_fp)) != EOF) {
    fputc(ch ^ password[i % pwd_len], crypt_fp);
    i++;
  }
  fclose(crypt_fp);
  fclose(normal_fp);
}


x86 assembly (clang, -O0):
<decrypt2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
je     11f0 <decrypt2+0xa0>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%eax
cltd
idivl  -0x34(%rbp)
mov    -0x40(%rbp),%rax
movslq %edx,%rcx
movsbl (%rax,%rcx,1),%eax
xor    %eax,%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    119f <decrypt2+0x4f>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrypt2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    0x2e4d(%rip),%r13
cmp    0x0(%r13),%eax
je     11d7 <decrypt2+0x87>
mov    %eax,%ecx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%eax
cltd
idiv   %ebp
movsbl (%r14,%rdx,1),%edi
xor    %ecx,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
add    $0x1,%ebx
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ecx
cmp    0x0(%r13),%eax
jne    11b0 <decrypt2+0x60>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@EOF = global i32 0
define void @decrypt2(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %8
store i32 0, i32* %10
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %11
br label %18
18: ; preds = %23, %3
%19 = load i32*, i32** %7
%20 = call i32 @fgetc(i32* %19)
store i32 %20, i32* %9
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %18
%24 = load i32, i32* %9
%25 = load i8*, i8** %6
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = srem i32 %26, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = xor i32 %24, %32
%34 = load i32*, i32** %8
%35 = call i32 @fputc(i32 %33, i32* %34)
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %18
38: ; preds = %18
%39 = load i32*, i32** %8
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %7
%42 = call i32 @fclose(i32* %41)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@EOF = global i32 0
define void @decrypt2(i8* nocapture %0, i8* nocapture %1, i8* %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* %2)
%7 = tail call i32 @fgetc(i32* %4)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %24, label %10
10: ; preds = %3, %10
%11 = phi i32 [ %21, %10 ], [ %7, %3 ]
%12 = phi i32 [ %20, %10 ], [ 0, %3 ]
%13 = srem i32 %12, %6
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %2, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = xor i32 %11, %17
%19 = tail call i32 @fputc(i32 %18, i32* %5)
%20 = add nuw nsw i32 %12, 1
%21 = tail call i32 @fgetc(i32* %4)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %10
24: ; preds = %10, %3
%25 = tail call i32 @fclose(i32* %5)
%26 = tail call i32 @fclose(i32* %4)
ret void
}