#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_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int upload(char *filename, char *name, int offset, int len) {
  char data;
  FILE *src;
  char tar_file_name[128] = "/etc/";
  char cmd[4120];
  char tmpdata[4096];
  int i = 0;
  strcat(tar_file_name, name);
  memset(cmd, 0, 4120);
  system(cmd);
  if (!(src = fopen(filename, "r"))) {
    printf("open src file error<br />\n");
    return 0;
  }
  if (fseek(src, offset, SEEK_SET) == -1) {
    printf("fseek error<br />\n");
    fclose(src);
    return 0;
  }
  memset(tmpdata, 0, 4096);
  while (len > 0) {
    if (!fread(&data, 1, 1, src))
      break;
    tmpdata[i] = data;
    len--;
    i++;
  }
  fclose(src);
  if (4096 < strlen(tmpdata)) {
    printf("Client Certificate is too big!<br />\n");
    fclose(src);
    return 0;
  }
  memset(cmd, 0, 4120);
  system(cmd);
  memset(cmd, 0, 4120);
  system(cmd);
  return 1;
}


x86 assembly (clang, -O0):
<upload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20e0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
movb   $0x2f,-0xb0(%rbp)
movb   $0x65,-0xaf(%rbp)
movb   $0x74,-0xae(%rbp)
movb   $0x63,-0xad(%rbp)
movb   $0x2f,-0xac(%rbp)
movl   $0x0,-0x20d4(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0x10d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1018,%edx
call   1080 <memset@plt>
lea    -0x10d0(%rbp),%rdi
call   1060 <system@plt>
mov    -0x10(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    124e <upload+0xbe>
lea    0xdc5(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1384 <upload+0x1f4>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
cmp    $0xffffffff,%eax
jne    128d <upload+0xfd>
lea    0xdaa(%rip),%rdi
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1384 <upload+0x1f4>
lea    -0x20d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
cmpl   $0x0,-0x20(%rbp)
jle    12fa <upload+0x16a>
mov    -0x30(%rbp),%rcx
lea    -0x21(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    12cc <upload+0x13c>
jmp    12fa <upload+0x16a>
mov    -0x21(%rbp),%cl
movslq -0x20d4(%rbp),%rax
mov    %cl,-0x20d0(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20d4(%rbp)
jmp    12a0 <upload+0x110>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x20d0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    $0x1000,%eax
cmp    %ecx,%eax
jge    133f <upload+0x1af>
lea    0xd0b(%rip),%rdi
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1384 <upload+0x1f4>
lea    -0x10d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1018,%edx
call   1080 <memset@plt>
lea    -0x10d0(%rbp),%rdi
call   1060 <system@plt>
lea    -0x10d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1018,%edx
call   1080 <memset@plt>
lea    -0x10d0(%rbp),%rdi
call   1060 <system@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upload>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20b0,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rdi,%r12
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movl   $0x6374652f,0x10(%rsp)
63
movb   $0x2f,0x14(%rsp)
lea    0x10(%rsp),%rdi
call   10b0 <strcat@plt>
lea    0x1090(%rsp),%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1018,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
lea    0xdeb(%rip),%rsi
mov    %r12,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12c3 <upload+0x133>
mov    %rax,%r12
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %r15d,%esi
call   1090 <fseek@plt>
cmp    $0xffffffff,%eax
je     12d1 <upload+0x141>
lea    0x90(%rsp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
test   %r14d,%r14d
jle    129e <upload+0x10e>
mov    %r14d,%ebp
xor    %ebx,%ebx
lea    0xf(%rsp),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     129e <upload+0x10e>
movzbl 0xf(%rsp),%eax
mov    %al,0x90(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1270 <upload+0xe0>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0x90(%rsp),%rdi
call   1060 <strlen@plt>
cmp    $0x1001,%eax
jl     12e9 <upload+0x159>
lea    0xd5b(%rip),%rdi
jmp    12d8 <upload+0x148>
lea    0xd38(%rip),%rdi
call   1030 <puts@plt>
jmp    1324 <upload+0x194>
lea    0xd69(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
jmp    1324 <upload+0x194>
lea    0x1090(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1018,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1018,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x20b0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"open src file error<br />\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [19 x i8] c"fseek error<br />\0A\00"
@.str.3 = [38 x i8] c"Client Certificate is too big!<br />\0A\00"
define i32 @upload(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32*
%12 = alloca [128 x i8]
%13 = alloca [4120 x i8]
%14 = alloca [4096 x i8]
%15 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%16 = bitcast [128 x i8]* %12 to i8*
%17 = bitcast i8* %16 to [128 x i8]*
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i32 0, i32 0
store i8 47, i8* %18
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i32 0, i32 1
store i8 101, i8* %19
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i32 0, i32 2
store i8 116, i8* %20
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i32 0, i32 3
store i8 99, i8* %21
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i32 0, i32 4
store i8 47, i8* %22
store i32 0, i32* %15
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%24 = load i8*, i8** %7
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = getelementptr inbounds [4120 x i8], [4120 x i8]* %13, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 4120)
%28 = getelementptr inbounds [4120 x i8], [4120 x i8]* %13, i64 0, i64 0
%29 = call i32 @system(i8* %28)
%30 = load i8*, i8** %6
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %31, i32** %11
%32 = icmp ne i32* %31, null
br i1 %32, label %35, label %33
33: ; preds = %4
%34 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %84
35: ; preds = %4
%36 = load i32*, i32** %11
%37 = load i32, i32* %8
%38 = load i32, i32* @SEEK_SET
%39 = call i32 @fseek(i32* %36, i32 %37, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32*, i32** %11
%44 = call i32 @fclose(i32* %43)
store i32 0, i32* %5
br label %84
45: ; preds = %35
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%47 = call i32 @memset(i8* %46, i32 0, i32 4096)
br label %48
48: ; preds = %56, %45
%49 = load i32, i32* %9
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %65
51: ; preds = %48
%52 = load i32*, i32** %11
%53 = call i32 @fread(i8* %10, i32 1, i32 1, i32* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %51
br label %65
56: ; preds = %51
%57 = load i8, i8* %10
%58 = load i32, i32* %15
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 %59
store i8 %57, i8* %60
%61 = load i32, i32* %9
%62 = add nsw i32 %61, -1
store i32 %62, i32* %9
%63 = load i32, i32* %15
%64 = add nsw i32 %63, 1
store i32 %64, i32* %15
br label %48
65: ; preds = %55, %48
%66 = load i32*, i32** %11
%67 = call i32 @fclose(i32* %66)
%68 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
%70 = icmp slt i32 4096, %69
br i1 %70, label %71, label %75
71: ; preds = %65
%72 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%73 = load i32*, i32** %11
%74 = call i32 @fclose(i32* %73)
store i32 0, i32* %5
br label %84
75: ; preds = %65
%76 = getelementptr inbounds [4120 x i8], [4120 x i8]* %13, i64 0, i64 0
%77 = call i32 @memset(i8* %76, i32 0, i32 4120)
%78 = getelementptr inbounds [4120 x i8], [4120 x i8]* %13, i64 0, i64 0
%79 = call i32 @system(i8* %78)
%80 = getelementptr inbounds [4120 x i8], [4120 x i8]* %13, i64 0, i64 0
%81 = call i32 @memset(i8* %80, i32 0, i32 4120)
%82 = getelementptr inbounds [4120 x i8], [4120 x i8]* %13, i64 0, i64 0
%83 = call i32 @system(i8* %82)
store i32 1, i32* %5
br label %84
84: ; preds = %75, %71, %41, %33
%85 = load i32, i32* %5
ret i32 %85
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@str = [26 x i8] c"open src file error<br />\00"
@str.4 = [37 x i8] c"Client Certificate is too big!<br />\00"
@str.5 = [18 x i8] c"fseek error<br />\00"
define i32 @upload(i8* nocapture %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8
%6 = alloca [128 x i8]
%7 = alloca [4120 x i8]
%8 = alloca [4096 x i8]
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
store i8 47, i8* %9
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 1
store i8 101, i8* %10
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 2
store i8 116, i8* %11
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 3
store i8 99, i8* %12
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 4
store i8 47, i8* %13
%14 = getelementptr inbounds [4120 x i8], [4120 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%16 = call i32 @strcat(i8* %9, i8* %1)
%17 = call i32 @memset(i8* %14, i32 0, i32 4120)
%18 = call i32 @system(i8* %14)
%19 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %4
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %56
23: ; preds = %4
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %19, i32 %2, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%29 = call i32 @fclose(i32* %19)
br label %56
30: ; preds = %23
%31 = call i32 @memset(i8* %15, i32 0, i32 4096)
%32 = icmp sgt i32 %3, 0
br i1 %32, label %33, label %44
33: ; preds = %30
%34 = zext i32 %3 to i64
br label %35
35: ; preds = %33, %39
%36 = phi i64 [ 0, %33 ], [ %42, %39 ]
%37 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %19)
%38 = icmp eq i32 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %35
%40 = load i8, i8* %5
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %36
store i8 %40, i8* %41
%42 = add nuw nsw i64 %36, 1
%43 = icmp eq i64 %42, %34
br i1 %43, label %44, label %35
44: ; preds = %39, %35, %30
%45 = call i32 @fclose(i32* %19)
%46 = call i32 @strlen(i8* %15)
%47 = icmp sgt i32 %46, 4096
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.4, i64 0, i64 0))
%50 = call i32 @fclose(i32* %19)
br label %56
51: ; preds = %44
%52 = call i32 @memset(i8* %14, i32 0, i32 4120)
%53 = call i32 @system(i8* %14)
%54 = call i32 @memset(i8* %14, i32 0, i32 4120)
%55 = call i32 @system(i8* %14)
br label %56
56: ; preds = %51, %48, %27, %21
%57 = phi i32 [ 0, %27 ], [ 0, %48 ], [ 1, %51 ], [ 0, %21 ]
ret i32 %57
}