#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 DesDec_raw(unsigned char *, int, unsigned char *, int *);
int DesEnc(unsigned char *, int, unsigned char *, int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int FileSymEnc(const char *pfile1, const char *pfile2) {
  int ret = 0;
  FILE *fp1 = NULL, *fp2 = NULL;
  unsigned char plain[4096];
  int plainlen = 0;
  unsigned char cryptbuf[4096] = {0};
  int cryptlen = 0;
  int tmplen;
  fp1 = fopen(pfile1, "rb");
  if (fp1 == NULL)
    goto END;
  fp2 = fopen(pfile2, "wb");
  if (fp2 == NULL)
    goto END;
  while (!feof(fp1)) {
    plainlen = fread(plain, 1, 4096, fp1);
    if (feof(fp1))
      break;
    ret = DesDec_raw(plain, plainlen, cryptbuf, &cryptlen);
    if (ret != 0) {
      printf("func DesEnc() err:%d \n", ret);
      goto END;
    }
    tmplen = fwrite(cryptbuf, 1, cryptlen, fp2);
    if (tmplen != cryptlen) {
      ret = -3;
      printf("Error occured while writing encrypted file, check the disk\n");
      goto END;
    }
  }
  ret = DesEnc(plain, plainlen, cryptbuf, &cryptlen);
  if (ret != 0) {
    printf("func DesEnc() err:%d \n", ret);
    goto END;
  }
  tmplen = fwrite(cryptbuf, 1, cryptlen, fp2);
  if (cryptlen != tmplen) {
    ret = -3;
    printf("Error occured while writing encrypted file, check the disk\n");
    goto END;
  }
END:
  if (fp1 != NULL)
    fclose(fp1);
  if (fp2 != NULL)
    fclose(fp2);
  return 0;
}


x86 assembly (clang, -O0):
<FileSymEnc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x1034(%rbp)
lea    -0x2040(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
movl   $0x0,-0x2044(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1205 <FileSymEnc+0x75>
jmp    13af <FileSymEnc+0x21f>
mov    -0x10(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1229 <FileSymEnc+0x99>
jmp    13af <FileSymEnc+0x21f>
jmp    122e <FileSymEnc+0x9e>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    124d <FileSymEnc+0xbd>
jmp    131a <FileSymEnc+0x18a>
lea    -0x1030(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x1034(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1285 <FileSymEnc+0xf5>
jmp    131a <FileSymEnc+0x18a>
lea    -0x1030(%rbp),%rdi
mov    -0x1034(%rbp),%esi
lea    -0x2040(%rbp),%rdx
lea    -0x2044(%rbp),%rcx
call   1090 <DesDec_raw@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12c8 <FileSymEnc+0x138>
mov    -0x14(%rbp),%esi
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13af <FileSymEnc+0x21f>
lea    -0x2040(%rbp),%rdi
mov    -0x2044(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    %eax,-0x2048(%rbp)
mov    -0x2048(%rbp),%eax
cmp    -0x2044(%rbp),%eax
je     1315 <FileSymEnc+0x185>
movl   $0xfffffffd,-0x14(%rbp)
lea    0xd14(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13af <FileSymEnc+0x21f>
jmp    122e <FileSymEnc+0x9e>
lea    -0x1030(%rbp),%rdi
mov    -0x1034(%rbp),%esi
lea    -0x2040(%rbp),%rdx
lea    -0x2044(%rbp),%rcx
call   1050 <DesEnc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     135d <FileSymEnc+0x1cd>
mov    -0x14(%rbp),%esi
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13af <FileSymEnc+0x21f>
lea    -0x2040(%rbp),%rdi
mov    -0x2044(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    %eax,-0x2048(%rbp)
mov    -0x2044(%rbp),%eax
cmp    -0x2048(%rbp),%eax
je     13aa <FileSymEnc+0x21a>
movl   $0xfffffffd,-0x14(%rbp)
lea    0xc7f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13af <FileSymEnc+0x21f>
jmp    13af <FileSymEnc+0x21f>
cmpq   $0x0,-0x20(%rbp)
je     13c3 <FileSymEnc+0x233>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     13d7 <FileSymEnc+0x247>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileSymEnc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1080 <memset@plt>
movl   $0x0,0xc(%rsp)
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1310 <FileSymEnc+0x170>
mov    %rax,%rbx
lea    0xe11(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1247 <FileSymEnc+0xa7>
mov    %rax,%r14
mov    %rbx,%rdi
call   1090 <feof@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     124f <FileSymEnc+0xaf>
lea    0x1010(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %ebp,%esi
call   1060 <DesEnc@plt>
test   %eax,%eax
je     12d8 <FileSymEnc+0x138>
lea    0xdcd(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1300 <FileSymEnc+0x160>
mov    %rbx,%r14
jmp    1308 <FileSymEnc+0x168>
lea    0x1010(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    1211 <FileSymEnc+0x71>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %r13,%rcx
call   10a0 <DesDec_raw@plt>
test   %eax,%eax
jne    1232 <FileSymEnc+0x92>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   10c0 <fwrite@plt>
cmp    0xc(%rsp),%eax
jne    12f4 <FileSymEnc+0x154>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
je     1270 <FileSymEnc+0xd0>
jmp    1211 <FileSymEnc+0x71>
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   10c0 <fwrite@plt>
cmp    %eax,0xc(%rsp)
je     1300 <FileSymEnc+0x160>
lea    0xd22(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [23 x i8] c"func DesEnc() err:%d \0A\00"
@.str.3 = [60 x i8] c"Error occured while writing encrypted file, check the disk\0A\00"
define i32 @FileSymEnc(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [4096 x i8]
%9 = alloca i32
%10 = alloca [4096 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32* null, i32** %6
store i32* null, i32** %7
store i32 0, i32* %9
%13 = bitcast [4096 x i8]* %10 to i8*
store i32 0, i32* %11
%14 = load i8*, i8** %3
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %2
br label %81
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %19
br label %81
25: ; preds = %19
br label %26
26: ; preds = %59, %25
%27 = load i32*, i32** %6
%28 = call i64 @feof(i32* %27)
%29 = icmp ne i64 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %60
31: ; preds = %26
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%33 = load i32*, i32** %6
%34 = call i32 @fread(i8* %32, i32 1, i32 4096, i32* %33)
store i32 %34, i32* %9
%35 = load i32*, i32** %6
%36 = call i64 @feof(i32* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %31
br label %60
39: ; preds = %31
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %9
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%43 = call i32 @DesDec_raw(i8* %40, i32 %41, i8* %42, i32* %11)
store i32 %43, i32* %5
%44 = load i32, i32* %5
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = load i32, i32* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %81
49: ; preds = %39
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%51 = load i32, i32* %11
%52 = load i32*, i32** %7
%53 = call i32 @fwrite(i8* %50, i32 1, i32 %51, i32* %52)
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = load i32, i32* %11
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %49
store i32 -3, i32* %5
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
br label %81
59: ; preds = %49
br label %26
60: ; preds = %38, %26
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%62 = load i32, i32* %9
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%64 = call i32 @DesEnc(i8* %61, i32 %62, i8* %63, i32* %11)
store i32 %64, i32* %5
%65 = load i32, i32* %5
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = load i32, i32* %5
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %68)
br label %81
70: ; preds = %60
%71 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%72 = load i32, i32* %11
%73 = load i32*, i32** %7
%74 = call i32 @fwrite(i8* %71, i32 1, i32 %72, i32* %73)
store i32 %74, i32* %12
%75 = load i32, i32* %11
%76 = load i32, i32* %12
%77 = icmp ne i32 %75, %76
br i1 %77, label %78, label %80
78: ; preds = %70
store i32 -3, i32* %5
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
br label %81
80: ; preds = %70
br label %81
81: ; preds = %80, %78, %67, %57, %46, %24, %18
%82 = load i32*, i32** %6
%83 = icmp ne i32* %82, null
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = load i32*, i32** %6
%86 = call i32 @fclose(i32* %85)
br label %87
87: ; preds = %84, %81
%88 = load i32*, i32** %7
%89 = icmp ne i32* %88, null
br i1 %89, label %90, label %93
90: ; preds = %87
%91 = load i32*, i32** %7
%92 = call i32 @fclose(i32* %91)
br label %93
93: ; preds = %90, %87
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [23 x i8] c"func DesEnc() err:%d \0A\00"
@str.4 = [59 x i8] c"Error occured while writing encrypted file, check the disk\00"
define i32 @FileSymEnc(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4096 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %54, label %11
11: ; preds = %2
%12 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %51, label %14
14: ; preds = %11
%15 = call i64 @feof(i32* %9)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %36
17: ; preds = %29
%18 = call i64 @feof(i32* %9)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %14, %17
%21 = call i32 @fread(i8* %6, i32 1, i32 4096, i32* %9)
%22 = call i64 @feof(i32* %9)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = call i32 @DesDec_raw(i8* %6, i32 %21, i8* %7, i32* %5)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %49
29: ; preds = %24
%30 = load i32, i32* %5
%31 = call i32 @fwrite(i8* %7, i32 1, i32 %30, i32* %12)
%32 = load i32, i32* %5
%33 = icmp eq i32 %31, %32
br i1 %33, label %17, label %34
34: ; preds = %29
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.4, i64 0, i64 0))
br label %49
36: ; preds = %17, %20, %14
%37 = phi i32 [ 0, %14 ], [ %21, %20 ], [ %21, %17 ]
%38 = call i32 @DesEnc(i8* %6, i32 %37, i8* %7, i32* %5)
%39 = icmp eq i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %49
42: ; preds = %36
%43 = load i32, i32* %5
%44 = call i32 @fwrite(i8* %7, i32 1, i32 %43, i32* %12)
%45 = load i32, i32* %5
%46 = icmp eq i32 %45, %44
br i1 %46, label %49, label %47
47: ; preds = %42
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.4, i64 0, i64 0))
br label %49
49: ; preds = %42, %47, %40, %34, %27
%50 = call i32 @fclose(i32* %9)
br label %51
51: ; preds = %49, %11
%52 = phi i32* [ %9, %11 ], [ %12, %49 ]
%53 = call i32 @fclose(i32* %52)
br label %54
54: ; preds = %51, %2
ret i32 0
}