#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;
typedef int /*<<< orphan*/ BF_KEY;

/* Variables and functions */
int /*<<< orphan*/ BF_ENCRYPT;
int /*<<< orphan*/ BF_cbc_encrypt(unsigned char *, unsigned char *, int,
                                  int /*<<< orphan*/ *, char *,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ BF_set_key(int /*<<< orphan*/ *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printHex(int, unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void encryptCBC(const char *inFileName, const char *outFileName) {
  BF_KEY key;
  FILE *inFile;
  FILE *outFile;
  unsigned char inBuffer[8];
  unsigned char outBuffer[8];
  int readBytes;
  char ivec[8];
  if ((inFile = fopen(inFileName, "r")) == NULL) {
    printf("Open file error occurred");
    exit(1);
  }
  if ((outFile = fopen(outFileName, "w")) == NULL) {
    printf("Open file error occurred");
    exit(1);
  }
  strncpy(ivec, "initvect", 8);
  BF_set_key(&key, strlen("1dqbfj4hgnr66534kjgrfs"), "1dqbfj4hgnr66534kjgrfs");
  while (1) {
    memset(inBuffer, 0, 8);
    if ((readBytes = fread(inBuffer, 1, 8, inFile)) == -1) {
      printf("Read error occurred");
    }
    if (readBytes == 0) {
      break;
    }
    if (readBytes < 8) {
      printf("Number of bytes read (last block): %i", readBytes);
      unsigned char padding = 8 - readBytes;
      printf(" -> padding aplied: %i\n", padding);
      int j = readBytes;
      for (j; j < 8; j++) {
        inBuffer[j] = padding;
      }
      readBytes = readBytes + padding;
    }
    BF_cbc_encrypt(inBuffer, outBuffer, 8, &key, ivec, BF_ENCRYPT);
    printHex(readBytes, outBuffer);
    fwrite(outBuffer, 1, 8, outFile);
  }
  fclose(inFile);
  fclose(outFile);
}


x86 assembly (clang, -O0):
<encryptCBC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1206 <encryptCBC+0x46>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    123c <encryptCBC+0x7c>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x44(%rbp),%rdi
lea    0xdd6(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    0xdce(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%esi
lea    -0x14(%rbp),%rdi
lea    0xdbc(%rip),%rdx
call   1080 <BF_set_key@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1040 <fread@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    12b0 <encryptCBC+0xf0>
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    12bf <encryptCBC+0xff>
jmp    1378 <encryptCBC+0x1b8>
cmpl   $0x8,-0x3c(%rbp)
jge    132c <encryptCBC+0x16c>
mov    -0x3c(%rbp),%esi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x8,%eax
sub    -0x3c(%rbp),%eax
mov    %al,-0x45(%rbp)
movzbl -0x45(%rbp),%esi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x8,-0x4c(%rbp)
jge    1320 <encryptCBC+0x160>
mov    -0x45(%rbp),%cl
movslq -0x4c(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    12fd <encryptCBC+0x13d>
mov    -0x3c(%rbp),%eax
movzbl -0x45(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x44(%rbp),%r8
mov    0x2ca1(%rip),%rax
mov    (%rax),%r9d
mov    $0x8,%edx
lea    -0x14(%rbp),%rcx
call   10a0 <BF_cbc_encrypt@plt>
mov    -0x3c(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10b0 <printHex@plt>
lea    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   10e0 <fwrite@plt>
jmp    126f <encryptCBC+0xaf>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encryptCBC>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
lea    0xe28(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1352 <encryptCBC+0x192>
mov    %rax,%r14
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1352 <encryptCBC+0x192>
mov    %rax,%r13
lea    0xe12(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    0xe05(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xc(%rsp),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1080 <BF_set_key@plt>
lea    0x18(%rsp),%rbx
lea    0x20(%rsp),%rbp
jmp    12ef <encryptCBC+0x12f>
nopw   0x0(%rax,%rax,1)
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdec(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x8,%al
sub    %r15b,%al
movzbl %al,%r12d
lea    0xdf8(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movslq %r15d,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x18,%rdi
mov    $0x7,%edx
sub    %r15d,%edx
add    $0x1,%rdx
mov    %r12d,%esi
call   1090 <memset@plt>
add    %r12d,%r15d
mov    0x2d2e(%rip),%rax
mov    (%rax),%r9d
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x8,%edx
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r8
call   10a0 <BF_cbc_encrypt@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   10b0 <printHex@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r13,%rcx
call   10e0 <fwrite@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     1250 <encryptCBC+0x90>
test   %r15d,%r15d
je     1333 <encryptCBC+0x173>
cmp    $0x7,%r15d
jle    125e <encryptCBC+0x9e>
jmp    12ab <encryptCBC+0xeb>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xca9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Open file error occurred\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"initvect\00"
@.str.4 = [23 x i8] c"1dqbfj4hgnr66534kjgrfs\00"
@.str.5 = [20 x i8] c"Read error occurred\00"
@.str.6 = [38 x i8] c"Number of bytes read (last block): %i\00"
@.str.7 = [24 x i8] c" -> padding aplied: %i\0A\00"
@BF_ENCRYPT = global i32 0
define void @encryptCBC(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [8 x i8]
%9 = alloca [8 x i8]
%10 = alloca i32
%11 = alloca [8 x i8]
%12 = alloca i8
%13 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%14 = load i8*, i8** %3
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%29 = call i32 @strncpy(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%30 = call i32 @strlen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @BF_set_key(i32* %5, i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %27, %75
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 8)
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%36 = load i32*, i32** %6
%37 = call i32 @fread(i8* %35, i32 1, i32 8, i32* %36)
store i32 %37, i32* %10
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %39, %32
%42 = load i32, i32* %10
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
br label %87
45: ; preds = %41
%46 = load i32, i32* %10
%47 = icmp slt i32 %46, 8
br i1 %47, label %48, label %75
48: ; preds = %45
%49 = load i32, i32* %10
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %10
%52 = sub nsw i32 8, %51
%53 = trunc i32 %52 to i8
store i8 %53, i8* %12
%54 = load i8, i8* %12
%55 = zext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %10
store i32 %57, i32* %13
%58 = load i32, i32* %13
br label %59
59: ; preds = %67, %48
%60 = load i32, i32* %13
%61 = icmp slt i32 %60, 8
br i1 %61, label %62, label %70
62: ; preds = %59
%63 = load i8, i8* %12
%64 = load i32, i32* %13
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 %65
store i8 %63, i8* %66
br label %67
67: ; preds = %62
%68 = load i32, i32* %13
%69 = add nsw i32 %68, 1
store i32 %69, i32* %13
br label %59
70: ; preds = %59
%71 = load i32, i32* %10
%72 = load i8, i8* %12
%73 = zext i8 %72 to i32
%74 = add nsw i32 %71, %73
store i32 %74, i32* %10
br label %75
75: ; preds = %70, %45
%76 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%77 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%78 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%79 = load i32, i32* @BF_ENCRYPT
%80 = call i32 @BF_cbc_encrypt(i8* %76, i8* %77, i32 8, i32* %5, i8* %78, i32 %79)
%81 = load i32, i32* %10
%82 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%83 = call i32 @printHex(i32 %81, i8* %82)
%84 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%85 = load i32*, i32** %7
%86 = call i32 @fwrite(i8* %84, i32 1, i32 8, i32* %85)
br label %32
87: ; preds = %44
%88 = load i32*, i32** %6
%89 = call i32 @fclose(i32* %88)
%90 = load i32*, i32** %7
%91 = call i32 @fclose(i32* %90)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Open file error occurred\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"initvect\00"
@.str.4 = [23 x i8] c"1dqbfj4hgnr66534kjgrfs\00"
@.str.5 = [20 x i8] c"Read error occurred\00"
@.str.6 = [38 x i8] c"Number of bytes read (last block): %i\00"
@.str.7 = [24 x i8] c" -> padding aplied: %i\0A\00"
@BF_ENCRYPT = global i32 0
define void @encryptCBC(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca [8 x i8]
%5 = alloca [8 x i8]
%6 = alloca [8 x i8]
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = call i32 @strncpy(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%24 = call i32 @strlen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @BF_set_key(i32* %3, i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %45, %22
%27 = call i32 @memset(i8* %8, i32 0, i32 8)
%28 = call i32 @fread(i8* %8, i32 1, i32 8, i32* %11)
switch i32 %28, label %31 [
i32 -1, label %29
i32 0, label %51
]
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %33
31: ; preds = %26
%32 = icmp slt i32 %28, 8
br i1 %32, label %33, label %45
33: ; preds = %29, %31
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%35 = trunc i32 %28 to i8
%36 = sub i8 8, %35
%37 = zext i8 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %37)
%39 = sext i32 %28 to i64
%40 = getelementptr [8 x i8], [8 x i8]* %4, i64 0, i64 %39
%41 = sub i32 7, %28
%42 = zext i32 %41 to i64
%43 = add nuw nsw i64 %42, 1
%44 = add nsw i32 %28, %37
br label %45
45: ; preds = %33, %31
%46 = phi i32 [ %44, %33 ], [ %28, %31 ]
%47 = load i32, i32* @BF_ENCRYPT
%48 = call i32 @BF_cbc_encrypt(i8* %8, i8* %9, i32 8, i32* %3, i8* %10, i32 %47)
%49 = call i32 @printHex(i32 %46, i8* %9)
%50 = call i32 @fwrite(i8* %9, i32 1, i32 8, i32* %17)
br label %26
51: ; preds = %26
%52 = call i32 @fclose(i32* %11)
%53 = call i32 @fclose(i32* %17)
ret void
}