#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ append_file_thread(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ progress_print(unsigned int *, int, scalar_t__);
scalar_t__ stat(char *, struct stat *);
void subfunc() {
  FILE *fp = NULL;
  struct stat stat_buf;
  char *p_file_buf = NULL;
  char buf[16] = {0};
  int read_size = 0;
  int total_read_size = 0;
  unsigned int prog_num = 0;
  if (0 != stat("test.txt", &stat_buf)) {
    ;
    goto exit;
  };
  if (0 >= stat_buf.st_size) {
    ;
    goto exit;
  }
  p_file_buf = (char *)malloc(stat_buf.st_size);
  fp = fopen("test.txt", "r");
  if (NULL == fp) {
    ;
    goto exit;
  }
  while (0 < (read_size = fread(buf, 1, sizeof(buf), fp))) {
    append_file_thread(buf, sizeof(buf));
    memcpy(&p_file_buf[total_read_size], buf, read_size);
    total_read_size += read_size;
    progress_print(&prog_num, total_read_size, stat_buf.st_size);
  }
exit:
  if (NULL != fp) {
    fclose(fp);
  }
  if (NULL != p_file_buf) {
    free(p_file_buf);
  };
  return;
}


x86 assembly (clang, -O0):
<subfunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    0xe1c(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1200 <subfunc+0x60>
jmp    12b9 <subfunc+0x119>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jl     1211 <subfunc+0x71>
jmp    12b9 <subfunc+0x119>
mov    -0x10(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xddb(%rip),%rdi
lea    0xddd(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    1246 <subfunc+0xa6>
jmp    12b9 <subfunc+0x119>
jmp    124b <subfunc+0xab>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1040 <fread@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jge    12b4 <subfunc+0x114>
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   1050 <append_file_thread@plt>
mov    -0x18(%rbp),%rdi
movslq -0x38(%rbp),%rax
add    %rax,%rdi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1090 <memcpy@plt>
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    -0x3c(%rbp),%rdi
call   10c0 <progress_print@plt>
jmp    124b <subfunc+0xab>
jmp    12b9 <subfunc+0x119>
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
je     12ce <subfunc+0x12e>
mov    -0x8(%rbp),%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     12e3 <subfunc+0x143>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subfunc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xe4b(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
jne    128f <subfunc+0xff>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
jle    128f <subfunc+0xff>
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0xe1b(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1282 <subfunc+0xf2>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    127a <subfunc+0xea>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0x10(%rsp),%r12
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x10,%esi
call   1050 <append_file_thread@plt>
movslq %ebx,%rbx
lea    (%r14,%rbx,1),%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1080 <memcpy@plt>
add    %ebp,%ebx
mov    0x8(%rsp),%rdx
mov    %r13,%rdi
mov    %ebx,%esi
call   10b0 <progress_print@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1230 <subfunc+0xa0>
mov    %r15,%rdi
call   1060 <fclose@plt>
test   %r14,%r14
je     128f <subfunc+0xff>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
define void @subfunc() {
%1 = alloca i32*
%2 = alloca %struct.stat
%3 = alloca i8*
%4 = alloca [16 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* null, i32** %1
store i8* null, i8** %3
%8 = bitcast [16 x i8]* %4 to i8*
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = call i64 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%10 = icmp ne i64 0, %9
br i1 %10, label %11, label %12
11: ; preds = %0
br label %50
12: ; preds = %0
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%14 = load i64, i64* %13
%15 = icmp sge i64 0, %14
br i1 %15, label %16, label %17
16: ; preds = %12
br label %50
17: ; preds = %12
%18 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%19 = load i64, i64* %18
%20 = call i64 @malloc(i64 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %3
%22 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %1
%23 = load i32*, i32** %1
%24 = icmp eq i32* null, %23
br i1 %24, label %25, label %26
25: ; preds = %17
br label %50
26: ; preds = %17
br label %27
27: ; preds = %32, %26
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%29 = load i32*, i32** %1
%30 = call i32 @fread(i8* %28, i32 1, i32 16, i32* %29)
store i32 %30, i32* %5
%31 = icmp slt i32 0, %30
br i1 %31, label %32, label %49
32: ; preds = %27
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%34 = call i32 @append_file_thread(i8* %33, i32 16)
%35 = load i8*, i8** %3
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%40 = load i32, i32* %5
%41 = call i32 @memcpy(i8* %38, i8* %39, i32 %40)
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = add nsw i32 %43, %42
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%47 = load i64, i64* %46
%48 = call i32 @progress_print(i32* %7, i32 %45, i64 %47)
br label %27
49: ; preds = %27
br label %50
50: ; preds = %49, %25, %16, %11
%51 = load i32*, i32** %1
%52 = icmp ne i32* null, %51
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32*, i32** %1
%55 = call i32 @fclose(i32* %54)
br label %56
56: ; preds = %53, %50
%57 = load i8*, i8** %3
%58 = icmp ne i8* null, %57
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i8*, i8** %3
%61 = call i32 @free(i8* %60)
br label %62
62: ; preds = %59, %56
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
define void @subfunc() {
%1 = alloca %struct.stat
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = bitcast %struct.stat* %1 to i8*
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = call i64 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%8 = icmp ne i64 %7, 0
%9 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%10 = load i64, i64* %9
%11 = icmp slt i64 %10, 1
%12 = select i1 %8, i1 true, i1 %11
br i1 %12, label %39, label %13
13: ; preds = %0
%14 = call i64 @malloc(i64 %10)
%15 = inttoptr i64 %14 to i8*
%16 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %35, label %18
18: ; preds = %13
%19 = call i32 @fread(i8* %5, i32 1, i32 16, i32* %16)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %18, %21
%22 = phi i32 [ %31, %21 ], [ %19, %18 ]
%23 = phi i32 [ %28, %21 ], [ 0, %18 ]
%24 = call i32 @append_file_thread(i8* %5, i32 16)
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %15, i64 %25
%27 = call i32 @memcpy(i8* %26, i8* %5, i32 %22)
%28 = add nsw i32 %22, %23
%29 = load i64, i64* %9
%30 = call i32 @progress_print(i32* %3, i32 %28, i64 %29)
%31 = call i32 @fread(i8* %5, i32 1, i32 16, i32* %16)
%32 = icmp sgt i32 %31, 0
br i1 %32, label %21, label %33
33: ; preds = %21, %18
%34 = call i32 @fclose(i32* %16)
br label %35
35: ; preds = %13, %33
%36 = icmp eq i64 %14, 0
br i1 %36, label %39, label %37
37: ; preds = %35
%38 = call i32 @free(i8* %15)
br label %39
39: ; preds = %0, %37, %35
ret void
}