#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 const *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
unsigned long strlen(char const *);
void fileEncryptDecryptWithPassword(const char *sourcePath,
                                    const char *targetPath,
                                    const char *password) {
  if (sourcePath == NULL || targetPath == NULL || password == NULL) {
    return;
  }
  FILE *rfile = fopen(sourcePath, "rb");
  FILE *wfile = fopen(targetPath, "wb");
  if (rfile == NULL || wfile == NULL) {
    return;
  }
  unsigned long passwordLength = strlen(password);
  int i = 0;
  int ch;
  while ((ch = fgetc(rfile)) != EOF) {
    ch = ch ^ (password[i % passwordLength]);
    fputc(ch, wfile);
    i++;
  }
  fclose(rfile);
  fclose(wfile);
}


x86 assembly (clang, -O0):
<fileEncryptDecryptWithPassword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1185 <fileEncryptDecryptWithPassword+0x35>
cmpq   $0x0,-0x10(%rbp)
je     1185 <fileEncryptDecryptWithPassword+0x35>
cmpq   $0x0,-0x18(%rbp)
jne    118a <fileEncryptDecryptWithPassword+0x3a>
jmp    1248 <fileEncryptDecryptWithPassword+0xf8>
mov    -0x8(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c8 <fileEncryptDecryptWithPassword+0x78>
cmpq   $0x0,-0x28(%rbp)
jne    11cd <fileEncryptDecryptWithPassword+0x7d>
jmp    1248 <fileEncryptDecryptWithPassword+0xf8>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x38(%rbp)
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%eax
je     1236 <fileEncryptDecryptWithPassword+0xe6>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rcx
movslq -0x34(%rbp),%rax
xor    %edx,%edx
divq   -0x30(%rbp)
mov    -0x3c(%rbp),%eax
movsbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e1 <fileEncryptDecryptWithPassword+0x91>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileEncryptDecryptWithPassword>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11d8 <fileEncryptDecryptWithPassword+0x88>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11d8 <fileEncryptDecryptWithPassword+0x88>
mov    %rdx,%r14
test   %rdx,%rdx
je     11d8 <fileEncryptDecryptWithPassword+0x88>
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %r12,%r12
je     11d8 <fileEncryptDecryptWithPassword+0x88>
mov    %rax,%r15
test   %rax,%rax
je     11d8 <fileEncryptDecryptWithPassword+0x88>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    0x2e33(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    11e7 <fileEncryptDecryptWithPassword+0x97>
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>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
xor    %ebx,%ebx
jmp    121a <fileEncryptDecryptWithPassword+0xca>
nopl   (%rax)
mov    %rbx,%rax
xor    %edx,%edx
div    %r13
movsbl (%r14,%rdx,1),%eax
xor    %eax,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    %eax,%edi
cmp    0x0(%rbp),%eax
je     11ba <fileEncryptDecryptWithPassword+0x6a>
mov    %rbx,%rax
or     %r13,%rax
shr    $0x20,%rax
jne    11f0 <fileEncryptDecryptWithPassword+0xa0>
mov    %ebx,%eax
xor    %edx,%edx
div    %r13d
jmp    11f8 <fileEncryptDecryptWithPassword+0xa8>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@EOF = global i32 0
define void @fileEncryptDecryptWithPassword(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%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 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %17, %14, %3
br label %61
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %7
%24 = load i8*, i8** %5
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %8
%26 = load i32*, i32** %7
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %21
%29 = load i32*, i32** %8
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %32
31: ; preds = %28, %21
br label %61
32: ; preds = %28
%33 = load i8*, i8** %6
%34 = call i64 @strlen(i8* %33)
store i64 %34, i64* %9
store i32 0, i32* %10
br label %35
35: ; preds = %40, %32
%36 = load i32*, i32** %7
%37 = call i32 @fgetc(i32* %36)
store i32 %37, i32* %11
%38 = load i32, i32* @EOF
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %56
40: ; preds = %35
%41 = load i32, i32* %11
%42 = load i8*, i8** %6
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = load i64, i64* %9
%46 = urem i64 %44, %45
%47 = getelementptr inbounds i8, i8* %42, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = xor i32 %41, %49
store i32 %50, i32* %11
%51 = load i32, i32* %11
%52 = load i32*, i32** %8
%53 = call i32 @fputc(i32 %51, i32* %52)
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %35
56: ; preds = %35
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %8
%60 = call i32 @fclose(i32* %59)
br label %61
61: ; preds = %56, %31, %20
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 @fileEncryptDecryptWithPassword(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i8* %2, null
%8 = or i1 %6, %7
br i1 %8, label %36, label %9
9: ; preds = %3
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %10, null
%13 = icmp eq i32* %11, null
%14 = or i1 %12, %13
br i1 %14, label %36, label %15
15: ; preds = %9
%16 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%17 = tail call i32 @fgetc(i32* %10)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %33, label %20
20: ; preds = %15, %20
%21 = phi i64 [ %29, %20 ], [ 0, %15 ]
%22 = phi i32 [ %30, %20 ], [ %17, %15 ]
%23 = urem i64 %21, %16
%24 = getelementptr inbounds i8, i8* %2, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = xor i32 %22, %26
%28 = tail call i32 @fputc(i32 %27, i32* %11)
%29 = add nuw i64 %21, 1
%30 = tail call i32 @fgetc(i32* %10)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %20
33: ; preds = %20, %15
%34 = tail call i32 @fclose(i32* %10)
%35 = tail call i32 @fclose(i32* %11)
br label %36
36: ; preds = %33, %9, %3
ret void
}