#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 /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int txtparser(char *srcfile, char *workspace, char *destpath) {
  char srcpath[1024] = {0};
  char respath[1024] = {0};
  sprintf(respath, "%s/temps/test.email.txt", workspace);
  sprintf(srcpath, "%s/%s/%s", workspace, destpath, srcfile);
  printf("********************%s********************\n", srcpath);
  FILE *from = NULL, *to = NULL;
  if ((from = fopen(srcpath, "rb")) != NULL) {
    char *txt_ptr = NULL;
    if ((to = fopen(respath, "ab")) == NULL) {
      printf("can't open file for decode attachment file , will give up this "
             "file\n");
      fclose(from);
      return -1;
    }
    {
      int NByte = 0;
      fseek(from, 0, SEEK_END);
      NByte = ftell(from);
      txt_ptr = (char *)malloc(NByte + 20);
      if (txt_ptr) {
        memset(txt_ptr, 0, 20 + NByte);
      } else {
        printf("can't malloc such huge page for loading txt\n");
        fclose(from);
        return -1;
      }
      fseek(from, 0, SEEK_SET);
      fread(txt_ptr, 1, NByte + 20 - 1, from);
      fwrite(txt_ptr, 1, strlen(txt_ptr), to);
      free(txt_ptr);
      txt_ptr = NULL;
    }
    fclose(to);
    fclose(from);
  }
  return 0;
}


x86 assembly (clang, -O0):
<txtparser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
lea    -0x420(%rbp),%rsi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x828(%rbp)
movq   $0x0,-0x830(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x828(%rbp)
cmp    $0x0,%rax
je     1411 <txtparser+0x251>
movq   $0x0,-0x838(%rbp)
lea    -0x820(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x830(%rbp)
cmp    $0x0,%rax
jne    12db <txtparser+0x11b>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x828(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1418 <txtparser+0x258>
movl   $0x0,-0x83c(%rbp)
mov    -0x828(%rbp),%rdi
mov    0x2cf5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x828(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x83c(%rbp)
mov    -0x83c(%rbp),%edi
add    $0x14,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x838(%rbp)
cmpq   $0x0,-0x838(%rbp)
je     134d <txtparser+0x18d>
mov    -0x838(%rbp),%rdi
mov    -0x83c(%rbp),%edx
add    $0x14,%edx
xor    %esi,%esi
call   1080 <memset@plt>
jmp    1373 <txtparser+0x1b3>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x828(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1418 <txtparser+0x258>
mov    -0x828(%rbp),%rdi
mov    0x2c57(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x838(%rbp),%rdi
mov    -0x83c(%rbp),%edx
add    $0x14,%edx
sub    $0x1,%edx
mov    -0x828(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x838(%rbp),%rax
mov    %rax,-0x848(%rbp)
mov    -0x838(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x848(%rbp),%rdi
mov    %eax,%edx
mov    -0x830(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x838(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x838(%rbp)
mov    -0x830(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x828(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txtparser>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r12
lea    0x400(%rsp),%r13
xor    %r14d,%r14d
mov    $0x400,%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
lea    0xde3(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   10e0 <sprintf@plt>
lea    0xde7(%rip),%rsi
mov    %r13,%rdi
mov    %rbp,%rdx
mov    %r15,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   10e0 <sprintf@plt>
lea    0xdd6(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdf1(%rip),%rsi
mov    %r13,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1347 <txtparser+0x177>
mov    %rax,%rbx
lea    0xdd9(%rip),%rsi
mov    %rsp,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1324 <txtparser+0x154>
mov    %rax,%r15
mov    0x2d56(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <ftell@plt>
mov    %eax,%r12d
lea    0x14(%r12),%r13d
mov    %r13d,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     132d <txtparser+0x15d>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   1090 <memset@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
add    $0x13,%r12d
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   10f0 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
jmp    133f <txtparser+0x16f>
lea    0xd54(%rip),%rdi
jmp    1334 <txtparser+0x164>
lea    0xd1f(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r14d
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14d,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"%s/temps/test.email.txt\00"
@.str.1 = [9 x i8] c"%s/%s/%s\00"
@.str.2 = [44 x i8] c"********************%s********************\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"ab\00"
@.str.5 = [69 x i8] c"can't open file for decode attachment file , will give up this file\0A\00"
@SEEK_END = global i32 0
@.str.6 = [45 x i8] c"can't malloc such huge page for loading txt\0A\00"
@SEEK_SET = global i32 0
define i32 @txtparser(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%14 = bitcast [1024 x i8]* %8 to i8*
%15 = bitcast [1024 x i8]* %9 to i8*
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = load i8*, i8** %5
%23 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21, i8* %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32* null, i32** %10
store i32* null, i32** %11
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %27, i32** %10
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %79
29: ; preds = %3
store i8* null, i8** %12
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %31, i32** %11
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.5, i64 0, i64 0))
%35 = load i32*, i32** %10
%36 = call i32 @fclose(i32* %35)
store i32 -1, i32* %4
br label %80
37: ; preds = %29
store i32 0, i32* %13
%38 = load i32*, i32** %10
%39 = load i32, i32* @SEEK_END
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = load i32*, i32** %10
%42 = call i32 @ftell(i32* %41)
store i32 %42, i32* %13
%43 = load i32, i32* %13
%44 = add nsw i32 %43, 20
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %12
%47 = load i8*, i8** %12
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %54
49: ; preds = %37
%50 = load i8*, i8** %12
%51 = load i32, i32* %13
%52 = add nsw i32 20, %51
%53 = call i32 @memset(i8* %50, i32 0, i32 %52)
br label %58
54: ; preds = %37
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%56 = load i32*, i32** %10
%57 = call i32 @fclose(i32* %56)
store i32 -1, i32* %4
br label %80
58: ; preds = %49
%59 = load i32*, i32** %10
%60 = load i32, i32* @SEEK_SET
%61 = call i32 @fseek(i32* %59, i32 0, i32 %60)
%62 = load i8*, i8** %12
%63 = load i32, i32* %13
%64 = add nsw i32 %63, 20
%65 = sub nsw i32 %64, 1
%66 = load i32*, i32** %10
%67 = call i32 @fread(i8* %62, i32 1, i32 %65, i32* %66)
%68 = load i8*, i8** %12
%69 = load i8*, i8** %12
%70 = call i32 @strlen(i8* %69)
%71 = load i32*, i32** %11
%72 = call i32 @fwrite(i8* %68, i32 1, i32 %70, i32* %71)
%73 = load i8*, i8** %12
%74 = call i32 @free(i8* %73)
store i8* null, i8** %12
%75 = load i32*, i32** %11
%76 = call i32 @fclose(i32* %75)
%77 = load i32*, i32** %10
%78 = call i32 @fclose(i32* %77)
br label %79
79: ; preds = %58, %3
store i32 0, i32* %4
br label %80
80: ; preds = %79, %54, %33
%81 = load i32, i32* %4
ret i32 %81
}

LLVM IR (-O2):
@.str = [24 x i8] c"%s/temps/test.email.txt\00"
@.str.1 = [9 x i8] c"%s/%s/%s\00"
@.str.2 = [44 x i8] c"********************%s********************\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"ab\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [44 x i8] c"can't malloc such huge page for loading txt\00"
@str.7 = [68 x i8] c"can't open file for decode attachment file , will give up this file\00"
define i32 @txtparser(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2, i8* %0)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%11 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %41, label %13
13: ; preds = %3
%14 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.7, i64 0, i64 0))
br label %38
18: ; preds = %13
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %11, i32 0, i32 %19)
%21 = call i32 @ftell(i32* %11)
%22 = add nsw i32 %21, 20
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = icmp eq i64 %23, 0
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
br label %38
28: ; preds = %18
%29 = call i32 @memset(i8* %24, i32 0, i32 %22)
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @fseek(i32* %11, i32 0, i32 %30)
%32 = add nsw i32 %21, 19
%33 = call i32 @fread(i8* %24, i32 1, i32 %32, i32* %11)
%34 = call i32 @strlen(i8* %24)
%35 = call i32 @fwrite(i8* %24, i32 1, i32 %34, i32* %14)
%36 = call i32 @free(i8* %24)
%37 = call i32 @fclose(i32* %14)
br label %38
38: ; preds = %16, %28, %26
%39 = phi i32 [ -1, %26 ], [ 0, %28 ], [ -1, %16 ]
%40 = call i32 @fclose(i32* %11)
br label %41
41: ; preds = %38, %3
%42 = phi i32 [ 0, %3 ], [ %39, %38 ]
ret i32 %42
}