#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 {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int PATH_MAX;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fstat(int, struct stat *);
char *getenv(char *);
int lseek(int, int, int /*<<< orphan*/);
char *malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int write(int, char *, int);
int main(int argc, const char **argv) {
  int fd1, fd2;
  char *buffer = NULL;
  int ret = 0;
  char *data = "append this content after test1";
  char file_path1[PATH_MAX], file_path2[PATH_MAX];
  const char *mount_point = getenv("CBB_CLIENT_MOUNT_POINT");
  struct stat filestat;
  if (NULL == mount_point) {
    fprintf(stderr, "please set CBB_CLIENT_MOUNT_POINT");
    return EXIT_FAILURE;
  }
  sprintf(file_path1, "%s%s", mount_point,
          "/montage/solvers/gxp_make/p2mass-atlas-990214n-j1200256_area.fits");
  sprintf(file_path2, "%s%s", mount_point, "/test2");
  if (-1 == (fd1 = open(file_path1, O_RDWR | O_CREAT | O_TRUNC, 0666))) {
    perror("open");
    return EXIT_FAILURE;
  }
  if (NULL == (buffer = malloc(4096 * sizeof(char)))) {
    perror("malloc");
    return EXIT_FAILURE;
  }
  if (-1 == fstat(fd1, &filestat)) {
    perror("fstat");
    return EXIT_FAILURE;
  }
  if (-1 == write(fd1, buffer, 2880 * sizeof(char))) {
    perror("write");
    return EXIT_FAILURE;
  }
  if (-1 == lseek(fd1, 0, SEEK_SET)) {
    perror("lseek");
    return EXIT_FAILURE;
  }
  if (-1 == lseek(fd1, 0, SEEK_SET)) {
    perror("lseek");
    return EXIT_FAILURE;
  }
  if (-1 == (ret = read(fd1, buffer, 4096 * sizeof(char)))) {
    perror("read");
    return EXIT_FAILURE;
  }
  printf("ret=%d\n", ret);
  buffer[34] = 0;
  printf("%s\n", buffer);
  if (-1 == read(fd2, buffer, sizeof(char))) {
    perror("read");
    return EXIT_FAILURE;
  }
  if (-1 == lseek(fd1, 35, SEEK_SET)) {
    perror("lseek");
    return EXIT_FAILURE;
  }
  if (-1 == write(fd1, data, strlen(data))) {
    perror("write");
    return EXIT_FAILURE;
  }
  close(fd1);
  close(fd2);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe01(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x70(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x40(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
lea    0xdd7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
cmp    -0x50(%rbp),%rax
jne    1296 <main+0xc6>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x70(%rbp),%rdi
mov    -0x50(%rbp),%rdx
lea    0xd9d(%rip),%rsi
lea    0xd9b(%rip),%rcx
call   10e0 <sprintf@plt>
mov    -0x68(%rbp),%rdi
mov    -0x50(%rbp),%rdx
lea    0xd82(%rip),%rsi
lea    0xdc2(%rip),%rcx
call   10e0 <sprintf@plt>
mov    -0x70(%rbp),%rdi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
mov    0x2d18(%rip),%rax
or     (%rax),%esi
mov    0x2d07(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10c0 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    132b <main+0x15b>
lea    0xd82(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    $0x1000,%edi
call   10b0 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    136b <main+0x19b>
lea    0xd47(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x14(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   10f0 <fstat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    13aa <main+0x1da>
lea    0xd0f(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0xb40,%edx
call   1040 <write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    13ee <main+0x21e>
lea    0xcd1(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2bd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x14(%rbp),%edi
mov    0x2bc0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1434 <main+0x264>
lea    0xc91(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x14(%rbp),%edi
mov    0x2b7a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    147a <main+0x2aa>
lea    0xc4b(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    14c1 <main+0x2f1>
lea    0xc0a(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x24(%rbp),%esi
lea    0xbe8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0x22(%rax)
mov    -0x20(%rbp),%rsi
lea    0xbd6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1530 <main+0x360>
lea    0xb9b(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2a91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x14(%rbp),%edi
mov    0x2a7e(%rip),%rax
mov    (%rax),%edx
mov    $0x23,%esi
call   1070 <lseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1579 <main+0x3a9>
lea    0xb4c(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2a48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x14(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    15d1 <main+0x401>
lea    0xaee(%rip),%rdi
call   10d0 <perror@plt>
mov    0x29f0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    15f4 <main+0x424>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
mov    0x29c0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe12(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1399 <main+0x1b9>
mov    %rax,%r15
lea    0xe11(%rip),%r12
lea    0xe0f(%rip),%rcx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   10f0 <sprintf@plt>
lea    0xe3c(%rip),%rcx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   10f0 <sprintf@plt>
mov    0x2d6e(%rip),%rax
mov    0x2d8f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d7c(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     13cb <main+0x1eb>
mov    %eax,%r14d
mov    $0x1000,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     13d4 <main+0x1f4>
mov    %rax,%rbx
lea    -0x28(%rbp),%rsi
mov    %r14d,%edi
call   1100 <fstat@plt>
cmp    $0xffffffff,%eax
je     13dd <main+0x1fd>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xb40,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
je     13c2 <main+0x1e2>
mov    0x2cde(%rip),%r15
mov    (%r15),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
je     13b0 <main+0x1d0>
mov    (%r15),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
je     13b0 <main+0x1d0>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   10a0 <read@plt>
cmp    $0xffffffff,%eax
je     13b9 <main+0x1d9>
lea    0xd8d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movb   $0x0,0x22(%rbx)
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
cmp    $0xffffffff,%eax
je     13b9 <main+0x1d9>
mov    (%r15),%edx
mov    %r14d,%edi
mov    $0x23,%esi
call   1080 <lseek@plt>
cmp    $0xffffffff,%eax
je     13b0 <main+0x1d0>
lea    0xc97(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
je     13c2 <main+0x1e2>
mov    %r14d,%edi
call   1090 <close@plt>
call   1090 <close@plt>
mov    0x2c11(%rip),%rax
jmp    13f0 <main+0x210>
mov    0x2c20(%rip),%rax
mov    (%rax),%edi
lea    0xc77(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    13e9 <main+0x209>
lea    0xcf1(%rip),%rdi
jmp    13e4 <main+0x204>
lea    0xcee(%rip),%rdi
jmp    13e4 <main+0x204>
lea    0xcd9(%rip),%rdi
jmp    13e4 <main+0x204>
lea    0xcbe(%rip),%rdi
jmp    13e4 <main+0x204>
lea    0xcba(%rip),%rdi
jmp    13e4 <main+0x204>
lea    0xcb8(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2bc0(%rip),%rax
mov    (%rax),%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [32 x i8] c"append this content after test1\00"
@PATH_MAX = global i32 0
@.str.1 = [23 x i8] c"CBB_CLIENT_MOUNT_POINT\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"please set CBB_CLIENT_MOUNT_POINT\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [66 x i8] c"/montage/solvers/gxp_make/p2mass-atlas-990214n-j1200256_area.fits\00"
@.str.5 = [7 x i8] c"/test2\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.6 = [5 x i8] c"open\00"
@.str.7 = [7 x i8] c"malloc\00"
@.str.8 = [6 x i8] c"fstat\00"
@.str.9 = [6 x i8] c"write\00"
@SEEK_SET = global i32 0
@.str.10 = [6 x i8] c"lseek\00"
@.str.11 = [5 x i8] c"read\00"
@.str.12 = [8 x i8] c"ret=%d\0A\00"
@.str.13 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
%15 = alloca %struct.stat
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i32 0, i32* %9
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %10
%17 = load i32, i32* @PATH_MAX
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %11
%20 = alloca i8, i64 %18
store i64 %18, i64* %12
%21 = load i32, i32* @PATH_MAX
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %13
%24 = call i8* @getenv(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i8* %24, i8** %14
%25 = load i8*, i8** %14
%26 = icmp eq i8* null, %25
br i1 %26, label %27, label %31
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
store i32 1, i32* %16
br label %129
31: ; preds = %2
%32 = load i8*, i8** %14
%33 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %32, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0))
%34 = load i8*, i8** %14
%35 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%36 = load i32, i32* @O_RDWR
%37 = load i32, i32* @O_CREAT
%38 = or i32 %36, %37
%39 = load i32, i32* @O_TRUNC
%40 = or i32 %38, %39
%41 = call i32 @open(i8* %20, i32 %40, i32 438)
store i32 %41, i32* %6
%42 = icmp eq i32 -1, %41
br i1 %42, label %43, label %46
43: ; preds = %31
%44 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
store i32 %45, i32* %3
store i32 1, i32* %16
br label %129
46: ; preds = %31
%47 = call i8* @malloc(i32 4096)
store i8* %47, i8** %8
%48 = icmp eq i8* null, %47
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
store i32 %51, i32* %3
store i32 1, i32* %16
br label %129
52: ; preds = %46
%53 = load i32, i32* %6
%54 = call i32 @fstat(i32 %53, %struct.stat* %15)
%55 = icmp eq i32 -1, %54
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
store i32 %58, i32* %3
store i32 1, i32* %16
br label %129
59: ; preds = %52
%60 = load i32, i32* %6
%61 = load i8*, i8** %8
%62 = call i32 @write(i32 %60, i8* %61, i32 2880)
%63 = icmp eq i32 -1, %62
br i1 %63, label %64, label %67
64: ; preds = %59
%65 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
store i32 %66, i32* %3
store i32 1, i32* %16
br label %129
67: ; preds = %59
%68 = load i32, i32* %6
%69 = load i32, i32* @SEEK_SET
%70 = call i32 @lseek(i32 %68, i32 0, i32 %69)
%71 = icmp eq i32 -1, %70
br i1 %71, label %72, label %75
72: ; preds = %67
%73 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
store i32 %74, i32* %3
store i32 1, i32* %16
br label %129
75: ; preds = %67
%76 = load i32, i32* %6
%77 = load i32, i32* @SEEK_SET
%78 = call i32 @lseek(i32 %76, i32 0, i32 %77)
%79 = icmp eq i32 -1, %78
br i1 %79, label %80, label %83
80: ; preds = %75
%81 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%82 = load i32, i32* @EXIT_FAILURE
store i32 %82, i32* %3
store i32 1, i32* %16
br label %129
83: ; preds = %75
%84 = load i32, i32* %6
%85 = load i8*, i8** %8
%86 = call i32 @read(i32 %84, i8* %85, i32 4096)
store i32 %86, i32* %9
%87 = icmp eq i32 -1, %86
br i1 %87, label %88, label %91
88: ; preds = %83
%89 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%90 = load i32, i32* @EXIT_FAILURE
store i32 %90, i32* %3
store i32 1, i32* %16
br label %129
91: ; preds = %83
%92 = load i32, i32* %9
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i32 %92)
%94 = load i8*, i8** %8
%95 = getelementptr inbounds i8, i8* %94, i64 34
store i8 0, i8* %95
%96 = load i8*, i8** %8
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i8* %96)
%98 = load i32, i32* %7
%99 = load i8*, i8** %8
%100 = call i32 @read(i32 %98, i8* %99, i32 1)
%101 = icmp eq i32 -1, %100
br i1 %101, label %102, label %105
102: ; preds = %91
%103 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%104 = load i32, i32* @EXIT_FAILURE
store i32 %104, i32* %3
store i32 1, i32* %16
br label %129
105: ; preds = %91
%106 = load i32, i32* %6
%107 = load i32, i32* @SEEK_SET
%108 = call i32 @lseek(i32 %106, i32 35, i32 %107)
%109 = icmp eq i32 -1, %108
br i1 %109, label %110, label %113
110: ; preds = %105
%111 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%112 = load i32, i32* @EXIT_FAILURE
store i32 %112, i32* %3
store i32 1, i32* %16
br label %129
113: ; preds = %105
%114 = load i32, i32* %6
%115 = load i8*, i8** %10
%116 = load i8*, i8** %10
%117 = call i32 @strlen(i8* %116)
%118 = call i32 @write(i32 %114, i8* %115, i32 %117)
%119 = icmp eq i32 -1, %118
br i1 %119, label %120, label %123
120: ; preds = %113
%121 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%122 = load i32, i32* @EXIT_FAILURE
store i32 %122, i32* %3
store i32 1, i32* %16
br label %129
123: ; preds = %113
%124 = load i32, i32* %6
%125 = call i32 @close(i32 %124)
%126 = load i32, i32* %7
%127 = call i32 @close(i32 %126)
%128 = load i32, i32* @EXIT_SUCCESS
store i32 %128, i32* %3
store i32 1, i32* %16
br label %129
129: ; preds = %123, %120, %110, %102, %88, %80, %72, %64, %56, %49, %43, %27
%130 = load i8*, i8** %11
%131 = load i32, i32* %3
ret i32 %131
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [32 x i8] c"append this content after test1\00"
@PATH_MAX = global i32 0
@.str.1 = [23 x i8] c"CBB_CLIENT_MOUNT_POINT\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"please set CBB_CLIENT_MOUNT_POINT\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [66 x i8] c"/montage/solvers/gxp_make/p2mass-atlas-990214n-j1200256_area.fits\00"
@.str.5 = [7 x i8] c"/test2\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.6 = [5 x i8] c"open\00"
@.str.7 = [7 x i8] c"malloc\00"
@.str.8 = [6 x i8] c"fstat\00"
@.str.9 = [6 x i8] c"write\00"
@SEEK_SET = global i32 0
@.str.10 = [6 x i8] c"lseek\00"
@.str.11 = [5 x i8] c"read\00"
@.str.12 = [8 x i8] c"ret=%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%9 = bitcast %struct.stat* %3 to i8*
%10 = icmp eq i8* %8, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %81
14: ; preds = %2
%15 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_CREAT
%19 = or i32 %18, %17
%20 = load i32, i32* @O_TRUNC
%21 = or i32 %19, %20
%22 = call i32 @open(i8* %6, i32 %21, i32 438)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %81
26: ; preds = %14
%27 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %81
31: ; preds = %26
%32 = call i32 @fstat(i32 %22, %struct.stat* %3)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %81
36: ; preds = %31
%37 = tail call i32 @write(i32 %22, i8* %27, i32 2880)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
br label %81
41: ; preds = %36
%42 = load i32, i32* @SEEK_SET
%43 = tail call i32 @lseek(i32 %22, i32 0, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %81
47: ; preds = %41
%48 = load i32, i32* @SEEK_SET
%49 = tail call i32 @lseek(i32 %22, i32 0, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %81
53: ; preds = %47
%54 = tail call i32 @read(i32 %22, i8* %27, i32 4096)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %81
58: ; preds = %53
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i32 %54)
%60 = getelementptr inbounds i8, i8* %27, i64 34
store i8 0, i8* %60
%61 = tail call i32 @puts(i8* %27)
%62 = tail call i32 @read(i32 undef, i8* %27, i32 1)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %58
%65 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %81
66: ; preds = %58
%67 = load i32, i32* @SEEK_SET
%68 = tail call i32 @lseek(i32 %22, i32 35, i32 %67)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %81
72: ; preds = %66
%73 = tail call i32 @strlen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%74 = tail call i32 @write(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %78
76: ; preds = %72
%77 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
br label %81
78: ; preds = %72
%79 = tail call i32 @close(i32 %22)
%80 = tail call i32 @close(i32 undef)
br label %81
81: ; preds = %78, %76, %70, %64, %56, %51, %45, %39, %34, %29, %24, %11
%82 = phi i32* [ @EXIT_FAILURE, %11 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_FAILURE, %29 ], [ @EXIT_FAILURE, %34 ], [ @EXIT_FAILURE, %39 ], [ @EXIT_FAILURE, %45 ], [ @EXIT_FAILURE, %51 ], [ @EXIT_FAILURE, %56 ], [ @EXIT_FAILURE, %64 ], [ @EXIT_FAILURE, %70 ], [ @EXIT_FAILURE, %76 ], [ @EXIT_SUCCESS, %78 ]
%83 = load i32, i32* %82
ret i32 %83
}