#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_ecb_encrypt(unsigned char *, unsigned char *,
                                  int /*<<< orphan*/ *, 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 *);
void encryptECB(const char *inFileName, const char *outFileName) {
  BF_KEY key;
  FILE *inFile;
  FILE *outFile;
  unsigned char inBuffer[8];
  unsigned char outBuffer[8];
  int readBytes;
  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);
  }
  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_ecb_encrypt(inBuffer, outBuffer, &key, BF_ENCRYPT);
    printHex(readBytes, outBuffer);
    fwrite(outBuffer, 1, 8, outFile);
  }
  fclose(inFile);
  fclose(outFile);
}


x86 assembly (clang, -O0):
<encryptECB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f6 <encryptECB+0x46>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    122c <encryptECB+0x7c>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xdea(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%esi
lea    -0x14(%rbp),%rdi
lea    0xdd8(%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   1030 <fread@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    128b <encryptECB+0xdb>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    129a <encryptECB+0xea>
jmp    1349 <encryptECB+0x199>
cmpl   $0x8,-0x3c(%rbp)
jge    1307 <encryptECB+0x157>
mov    -0x3c(%rbp),%esi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x8,%eax
sub    -0x3c(%rbp),%eax
mov    %al,-0x3d(%rbp)
movzbl -0x3d(%rbp),%esi
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x8,-0x44(%rbp)
jge    12fb <encryptECB+0x14b>
mov    -0x3d(%rbp),%cl
movslq -0x44(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12d8 <encryptECB+0x128>
mov    -0x3c(%rbp),%eax
movzbl -0x3d(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    0x2cca(%rip),%rax
mov    (%rax),%ecx
lea    -0x14(%rbp),%rdx
call   1040 <BF_ecb_encrypt@plt>
mov    -0x3c(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10a0 <printHex@plt>
lea    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   10d0 <fwrite@plt>
jmp    124a <encryptECB+0x9a>
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):
<encryptECB>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
lea    0xe38(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1324 <encryptECB+0x174>
mov    %rax,%r14
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1324 <encryptECB+0x174>
mov    %rax,%r12
lea    0xe22(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x4(%rsp),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1080 <BF_set_key@plt>
lea    0x8(%rsp),%rbx
lea    0x10(%rsp),%rbp
jmp    12c4 <encryptECB+0x114>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xdfd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe03(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x8,%al
sub    %r13b,%al
movzbl %al,%r15d
lea    0xe0f(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movslq %r13d,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x8,%rdi
mov    $0x7,%edx
sub    %r13d,%edx
add    $0x1,%rdx
mov    %r15d,%esi
call   1090 <memset@plt>
add    %r15d,%r13d
mov    0x2d4e(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %rbp,%rsi
lea    0x4(%rsp),%rdx
call   1040 <BF_ecb_encrypt@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
call   10a0 <printHex@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r12,%rcx
call   10d0 <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   1030 <fread@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     1230 <encryptECB+0x80>
test   %r13d,%r13d
je     1305 <encryptECB+0x155>
cmp    $0x7,%r13d
jle    123e <encryptECB+0x8e>
jmp    128b <encryptECB+0xdb>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcd7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10c0 <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 = [23 x i8] c"1dqbfj4hgnr66534kjgrfs\00"
@.str.4 = [20 x i8] c"Read error occurred\00"
@.str.5 = [38 x i8] c"Number of bytes read (last block): %i\00"
@.str.6 = [24 x i8] c" -> padding aplied: %i\0A\00"
@BF_ENCRYPT = global i32 0
define void @encryptECB(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 i8
%12 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %21, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = call i32 @strlen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @BF_set_key(i32* %5, i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %26, %72
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%31 = call i32 @memset(i8* %30, i32 0, i32 8)
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%33 = load i32*, i32** %6
%34 = call i32 @fread(i8* %32, i32 1, i32 8, i32* %33)
store i32 %34, i32* %10
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %29
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
br label %83
42: ; preds = %38
%43 = load i32, i32* %10
%44 = icmp slt i32 %43, 8
br i1 %44, label %45, label %72
45: ; preds = %42
%46 = load i32, i32* %10
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %10
%49 = sub nsw i32 8, %48
%50 = trunc i32 %49 to i8
store i8 %50, i8* %11
%51 = load i8, i8* %11
%52 = zext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %10
store i32 %54, i32* %12
%55 = load i32, i32* %12
br label %56
56: ; preds = %64, %45
%57 = load i32, i32* %12
%58 = icmp slt i32 %57, 8
br i1 %58, label %59, label %67
59: ; preds = %56
%60 = load i8, i8* %11
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 %62
store i8 %60, i8* %63
br label %64
64: ; preds = %59
%65 = load i32, i32* %12
%66 = add nsw i32 %65, 1
store i32 %66, i32* %12
br label %56
67: ; preds = %56
%68 = load i32, i32* %10
%69 = load i8, i8* %11
%70 = zext i8 %69 to i32
%71 = add nsw i32 %68, %70
store i32 %71, i32* %10
br label %72
72: ; preds = %67, %42
%73 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%74 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%75 = load i32, i32* @BF_ENCRYPT
%76 = call i32 @BF_ecb_encrypt(i8* %73, i8* %74, i32* %5, i32 %75)
%77 = load i32, i32* %10
%78 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%79 = call i32 @printHex(i32 %77, i8* %78)
%80 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%81 = load i32*, i32** %7
%82 = call i32 @fwrite(i8* %80, i32 1, i32 8, i32* %81)
br label %29
83: ; preds = %41
%84 = load i32*, i32** %6
%85 = call i32 @fclose(i32* %84)
%86 = load i32*, i32** %7
%87 = call i32 @fclose(i32* %86)
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 = [23 x i8] c"1dqbfj4hgnr66534kjgrfs\00"
@.str.4 = [20 x i8] c"Read error occurred\00"
@.str.5 = [38 x i8] c"Number of bytes read (last block): %i\00"
@.str.6 = [24 x i8] c" -> padding aplied: %i\0A\00"
@BF_ENCRYPT = global i32 0
define void @encryptECB(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca [8 x i8]
%5 = alloca [8 x i8]
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %14
%21 = tail call i32 @strlen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @BF_set_key(i32* %3, i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %42, %20
%24 = call i32 @memset(i8* %7, i32 0, i32 8)
%25 = call i32 @fread(i8* %7, i32 1, i32 8, i32* %9)
switch i32 %25, label %28 [
i32 -1, label %26
i32 0, label %48
]
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %30
28: ; preds = %23
%29 = icmp slt i32 %25, 8
br i1 %29, label %30, label %42
30: ; preds = %26, %28
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%32 = trunc i32 %25 to i8
%33 = sub i8 8, %32
%34 = zext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %34)
%36 = sext i32 %25 to i64
%37 = getelementptr [8 x i8], [8 x i8]* %4, i64 0, i64 %36
%38 = sub i32 7, %25
%39 = zext i32 %38 to i64
%40 = add nuw nsw i64 %39, 1
%41 = add nsw i32 %25, %34
br label %42
42: ; preds = %30, %28
%43 = phi i32 [ %41, %30 ], [ %25, %28 ]
%44 = load i32, i32* @BF_ENCRYPT
%45 = call i32 @BF_ecb_encrypt(i8* %7, i8* %8, i32* %3, i32 %44)
%46 = call i32 @printHex(i32 %43, i8* %8)
%47 = call i32 @fwrite(i8* %8, i32 1, i32 8, i32* %15)
br label %23
48: ; preds = %23
%49 = call i32 @fclose(i32* %9)
%50 = call i32 @fclose(i32* %15)
ret void
}