#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 dirent {
  scalar_t__ d_type;
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_DIR;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IROTH;
int S_IRUSR;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
size_t getfilesize_fd(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
size_t read(int, char *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
size_t strlen(char *);
char *strstr(char *, char *);
size_t write(int, char *, size_t);
void bufferedpackindexfd(char *devname) {
  int fdpackfile;
  fdpackfile = open(devname, O_WRONLY | O_CREAT | O_TRUNC,
                    S_IROTH | S_IWOTH | S_IRUSR | S_IWUSR);
  if (fdpackfile <= 0) {
    printf("*** ZVM Error open packfile (write)%s\n", devname);
    return;
  }
  char *indexpath = (char *)"index";
  DIR *dir;
  struct dirent *entry;
  dir = opendir(indexpath);
  char *newpath;
  if (!dir)
    printf("*** ZVM Error open DIR %s\n", indexpath);
  int blocksize = 1024 * 64;
  char *buff = NULL;
  buff = (char *)malloc(blocksize);
  long deltabytes = 0;
  long mainbytes = 0;
  int filecount = 0;
  while ((entry = readdir(dir))) {
    if (entry->d_type != DT_DIR) {
      size_t size;
      size_t bread = 0;
      size_t bwrite;
      size_t bytecount;
      bytecount = 0;
      newpath = (char *)malloc(strlen(entry->d_name) + strlen(indexpath) + 2);
      sprintf(newpath, "%s/%s", indexpath, entry->d_name);
      int fd;
      fd = open(newpath, O_RDONLY);
      size = getfilesize_fd(fd, NULL, 0);
      char tempstr[strlen(newpath) * 2 + 50];
      sprintf(tempstr, "{%zu %s}\n", size, newpath);
      bwrite = write(fdpackfile, tempstr, strlen(tempstr));
      if (size > 0) {
        while ((bread = read(fd, buff, blocksize)) > 0) {
          bytecount += bread;
          bwrite = write(fdpackfile, buff, bread);
        }
      } else
        bytecount = 0;
      sprintf(tempstr, "{%s}\n", newpath);
      bwrite = write(fdpackfile, tempstr, strlen(tempstr));
      close(fd);
      char *indexnameptr = NULL;
      if ((indexnameptr = strstr(newpath, "deltaindex")) != NULL)
        deltabytes += size;
      indexnameptr = NULL;
      if ((indexnameptr = strstr(newpath, "mainindex")) != NULL)
        mainbytes += size;
      filecount++;
    }
  }
  free(buff);
  close(fdpackfile);
}


x86 assembly (clang, -O0):
<bufferedpackindexfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
mov    0x2e05(%rip),%rax
or     (%rax),%esi
mov    0x2df4(%rip),%rax
or     (%rax),%esi
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
mov    0x2d8a(%rip),%rax
or     (%rax),%edx
mov    0x2d99(%rip),%rax
or     (%rax),%edx
mov    0x2db0(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     124b <bufferedpackindexfd+0x7b>
mov    -0x8(%rbp),%rsi
lea    0xdbf(%rip),%rdi
call   1080 <printf@plt>
jmp    1549 <bufferedpackindexfd+0x379>
lea    0xe0b(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127e <bufferedpackindexfd+0xae>
mov    -0x18(%rbp),%rsi
lea    0xdae(%rip),%rdi
call   1080 <printf@plt>
movl   $0x10000,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x34(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1538 <bufferedpackindexfd+0x368>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2ceb(%rip),%rcx
cmp    (%rcx),%rax
je     1533 <bufferedpackindexfd+0x363>
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %rax,-0xb8(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0xb8(%rbp),%rax
mov    %ecx,%edx
mov    %eax,%ecx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x2(%rax,%rcx,1),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xd01(%rip),%rsi
xor    %eax,%eax
mov    %eax,-0xa8(%rbp)
mov    %al,-0xa9(%rbp)
call   10e0 <sprintf@plt>
mov    -0xa9(%rbp),%al
mov    -0x30(%rbp),%rdi
mov    0x2c73(%rip),%rcx
mov    (%rcx),%esi
call   10d0 <open@plt>
mov    -0xa8(%rbp),%edx
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%edi
mov    %edx,%esi
call   1040 <getfilesize_fd@plt>
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
lea    0x32(%rcx,%rcx,1),%rax
mov    %rsp,%rdx
mov    %rdx,-0x88(%rbp)
lea    0x41(%rcx,%rcx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0xa0(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x90(%rbp)
mov    -0x60(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xc7b(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0xa0(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    %eax,-0xa4(%rbp)
call   1070 <strlen@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    %rax,%rdx
call   1050 <write@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x60(%rbp)
jbe    1459 <bufferedpackindexfd+0x289>
jmp    1412 <bufferedpackindexfd+0x242>
mov    -0x7c(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   10a0 <read@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jbe    1454 <bufferedpackindexfd+0x284>
mov    -0x68(%rbp),%rax
add    -0x78(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x68(%rbp),%rdx
call   1050 <write@plt>
mov    %rax,-0x70(%rbp)
jmp    1412 <bufferedpackindexfd+0x242>
jmp    1461 <bufferedpackindexfd+0x291>
movq   $0x0,-0x78(%rbp)
mov    -0xa0(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xbdf(%rip),%rsi
mov    $0x0,%al
call   10e0 <sprintf@plt>
mov    -0xa0(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    %eax,-0xbc(%rbp)
call   1070 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    %rax,%rdx
call   1050 <write@plt>
mov    %rax,-0x70(%rbp)
mov    -0x7c(%rbp),%edi
call   1090 <close@plt>
movq   $0x0,-0x98(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xb92(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
je     14e8 <bufferedpackindexfd+0x318>
mov    -0x60(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x98(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xb65(%rip),%rsi
call   10f0 <strstr@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
je     1520 <bufferedpackindexfd+0x350>
mov    -0x60(%rbp),%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,%rsp
jmp    12b0 <bufferedpackindexfd+0xe0>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferedpackindexfd>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2dc8(%rip),%rax
mov    0x2e19(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e06(%rip),%rax
or     (%rax),%esi
mov    0x2dc5(%rip),%rax
mov    0x2d9e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dab(%rip),%rax
or     (%rax),%edx
mov    %rdi,%rbx
mov    0x2dbf(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
jle    13e7 <bufferedpackindexfd+0x227>
mov    %eax,%r15d
lea    0xdfb(%rip),%rdi
call   1060 <opendir@plt>
mov    %rax,%r14
test   %rax,%rax
jne    124c <bufferedpackindexfd+0x8c>
lea    0xded(%rip),%rdi
lea    0xde0(%rip),%rsi
call   1080 <printf@plt>
mov    $0x10000,%edi
call   10c0 <malloc@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     13c9 <bufferedpackindexfd+0x209>
mov    %rax,%rbx
mov    0x2d4c(%rip),%r13
mov    %r14,-0x38(%rbp)
mov    %r15d,-0x2c(%rbp)
jmp    12d6 <bufferedpackindexfd+0x116>
xchg   %ax,%ax
mov    %r14,%rdi
lea    0xdce(%rip),%rsi
mov    -0x48(%rbp),%rdx
xor    %eax,%eax
call   10e0 <sprintf@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1050 <write@plt>
mov    %r13d,%edi
call   1090 <close@plt>
mov    -0x40(%rbp),%rsp
mov    -0x38(%rbp),%r14
mov    0x2cfe(%rip),%r13
mov    %r14,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     13c9 <bufferedpackindexfd+0x209>
mov    (%rbx),%rax
cmp    0x0(%r13),%rax
je     12c2 <bufferedpackindexfd+0x102>
mov    0x8(%rbx),%rdi
call   1070 <strlen@plt>
lea    0x7(%rax),%edi
call   10c0 <malloc@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rcx
mov    %rax,%rdi
lea    0xd47(%rip),%rsi
lea    0xd1f(%rip),%rdx
xor    %eax,%eax
call   10e0 <sprintf@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   10d0 <open@plt>
mov    %eax,%r13d
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <getfilesize_fd@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %rsp,-0x40(%rbp)
mov    %rsp,%r14
add    %rax,%rax
add    $0x41,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
lea    0xcf1(%rip),%rsi
mov    %rbx,%rdx
mov    %r15,-0x48(%rbp)
mov    %r15,%rcx
mov    -0x2c(%rbp),%r15d
xor    %eax,%eax
call   10e0 <sprintf@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1050 <write@plt>
test   %rbx,%rbx
je     1280 <bufferedpackindexfd+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x10000,%edx
call   10a0 <read@plt>
test   %rax,%rax
je     1280 <bufferedpackindexfd+0xc0>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %rax,%rdx
call   1050 <write@plt>
jmp    13a0 <bufferedpackindexfd+0x1e0>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <close@plt>
lea    0xc12(%rip),%rdi
mov    %rbx,%rsi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <printf@plt>

LLVM IR (-O0):
%struct.dirent = type { i64, i8* }
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [39 x i8] c"*** ZVM Error open packfile (write)%s\0A\00"
@.str.1 = [6 x i8] c"index\00"
@.str.2 = [27 x i8] c"*** ZVM Error open DIR %s\0A\00"
@DT_DIR = global i64 0
@.str.3 = [6 x i8] c"%s/%s\00"
@O_RDONLY = global i32 0
@.str.4 = [10 x i8] c"{%zu %s}\0A\00"
@.str.5 = [6 x i8] c"{%s}\0A\00"
@.str.6 = [11 x i8] c"deltaindex\00"
@.str.7 = [10 x i8] c"mainindex\00"
define void @bufferedpackindexfd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i8*
store i8* %0, i8** %2
%21 = load i8*, i8** %2
%22 = load i32, i32* @O_WRONLY
%23 = load i32, i32* @O_CREAT
%24 = or i32 %22, %23
%25 = load i32, i32* @O_TRUNC
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IROTH
%28 = load i32, i32* @S_IWOTH
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IRUSR
%31 = or i32 %29, %30
%32 = load i32, i32* @S_IWUSR
%33 = or i32 %31, %32
%34 = call i32 (i8*, i32, ...) @open(i8* %21, i32 %26, i32 %33)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp sle i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %1
%38 = load i8*, i8** %2
%39 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %38)
br label %149
40: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %4
%41 = load i8*, i8** %4
%42 = call i32* @opendir(i8* %41)
store i32* %42, i32** %5
%43 = load i32*, i32** %5
%44 = icmp ne i32* %43, null
br i1 %44, label %48, label %45
45: ; preds = %40
%46 = load i8*, i8** %4
%47 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %45, %40
store i32 65536, i32* %8
store i8* null, i8** %9
%49 = load i32, i32* %8
%50 = call i64 @malloc(i32 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %9
store i64 0, i64* %10
store i64 0, i64* %11
store i32 0, i32* %12
br label %52
52: ; preds = %143, %48
%53 = load i32*, i32** %5
%54 = call %struct.dirent* @readdir(i32* %53)
store %struct.dirent* %54, %struct.dirent** %6
%55 = icmp ne %struct.dirent* %54, null
br i1 %55, label %56, label %144
56: ; preds = %52
%57 = load %struct.dirent*, %struct.dirent** %6
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 0
%59 = load i64, i64* %58
%60 = load i64, i64* @DT_DIR
%61 = icmp ne i64 %59, %60
br i1 %61, label %62, label %143
62: ; preds = %56
store i64 0, i64* %14
store i64 0, i64* %16
%63 = load %struct.dirent*, %struct.dirent** %6
%64 = getelementptr inbounds %struct.dirent, %struct.dirent* %63, i32 0, i32 1
%65 = load i8*, i8** %64
%66 = call i64 @strlen(i8* %65)
%67 = load i8*, i8** %4
%68 = call i64 @strlen(i8* %67)
%69 = add i64 %66, %68
%70 = add i64 %69, 2
%71 = trunc i64 %70 to i32
%72 = call i64 @malloc(i32 %71)
%73 = inttoptr i64 %72 to i8*
store i8* %73, i8** %7
%74 = load i8*, i8** %7
%75 = load i8*, i8** %4
%76 = load %struct.dirent*, %struct.dirent** %6
%77 = getelementptr inbounds %struct.dirent, %struct.dirent* %76, i32 0, i32 1
%78 = load i8*, i8** %77
%79 = call i32 (i8*, i8*, ...) @sprintf(i8* %74, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %78)
%80 = load i8*, i8** %7
%81 = load i32, i32* @O_RDONLY
%82 = call i32 (i8*, i32, ...) @open(i8* %80, i32 %81)
store i32 %82, i32* %17
%83 = load i32, i32* %17
%84 = call i64 @getfilesize_fd(i32 %83, i32* null, i32 0)
store i64 %84, i64* %13
%85 = load i8*, i8** %7
%86 = call i64 @strlen(i8* %85)
%87 = mul i64 %86, 2
%88 = add i64 %87, 50
%89 = call i8* @llvm.stacksave()
store i8* %89, i8** %18
%90 = alloca i8, i64 %88
store i64 %88, i64* %19
%91 = load i64, i64* %13
%92 = load i8*, i8** %7
%93 = call i32 (i8*, i8*, ...) @sprintf(i8* %90, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i64 %91, i8* %92)
%94 = load i32, i32* %3
%95 = call i64 @strlen(i8* %90)
%96 = call i64 @write(i32 %94, i8* %90, i64 %95)
store i64 %96, i64* %15
%97 = load i64, i64* %13
%98 = icmp ugt i64 %97, 0
br i1 %98, label %99, label %115
99: ; preds = %62
br label %100
100: ; preds = %106, %99
%101 = load i32, i32* %17
%102 = load i8*, i8** %9
%103 = load i32, i32* %8
%104 = call i64 @read(i32 %101, i8* %102, i32 %103)
store i64 %104, i64* %14
%105 = icmp ugt i64 %104, 0
br i1 %105, label %106, label %114
106: ; preds = %100
%107 = load i64, i64* %14
%108 = load i64, i64* %16
%109 = add i64 %108, %107
store i64 %109, i64* %16
%110 = load i32, i32* %3
%111 = load i8*, i8** %9
%112 = load i64, i64* %14
%113 = call i64 @write(i32 %110, i8* %111, i64 %112)
store i64 %113, i64* %15
br label %100
114: ; preds = %100
br label %116
115: ; preds = %62
store i64 0, i64* %16
br label %116
116: ; preds = %115, %114
%117 = load i8*, i8** %7
%118 = call i32 (i8*, i8*, ...) @sprintf(i8* %90, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %117)
%119 = load i32, i32* %3
%120 = call i64 @strlen(i8* %90)
%121 = call i64 @write(i32 %119, i8* %90, i64 %120)
store i64 %121, i64* %15
%122 = load i32, i32* %17
%123 = call i32 @close(i32 %122)
store i8* null, i8** %20
%124 = load i8*, i8** %7
%125 = call i8* @strstr(i8* %124, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
store i8* %125, i8** %20
%126 = icmp ne i8* %125, null
br i1 %126, label %127, label %131
127: ; preds = %116
%128 = load i64, i64* %13
%129 = load i64, i64* %10
%130 = add i64 %129, %128
store i64 %130, i64* %10
br label %131
131: ; preds = %127, %116
store i8* null, i8** %20
%132 = load i8*, i8** %7
%133 = call i8* @strstr(i8* %132, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
store i8* %133, i8** %20
%134 = icmp ne i8* %133, null
br i1 %134, label %135, label %139
135: ; preds = %131
%136 = load i64, i64* %13
%137 = load i64, i64* %11
%138 = add i64 %137, %136
store i64 %138, i64* %11
br label %139
139: ; preds = %135, %131
%140 = load i32, i32* %12
%141 = add nsw i32 %140, 1
store i32 %141, i32* %12
%142 = load i8*, i8** %18
br label %143
143: ; preds = %139, %56
br label %52
144: ; preds = %52
%145 = load i8*, i8** %9
%146 = call i32 @free(i8* %145)
%147 = load i32, i32* %3
%148 = call i32 @close(i32 %147)
br label %149
149: ; preds = %144, %37
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i64, i8* }
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [39 x i8] c"*** ZVM Error open packfile (write)%s\0A\00"
@.str.1 = [6 x i8] c"index\00"
@.str.2 = [27 x i8] c"*** ZVM Error open DIR %s\0A\00"
@DT_DIR = global i64 0
@.str.3 = [6 x i8] c"%s/%s\00"
@O_RDONLY = global i32 0
@.str.4 = [10 x i8] c"{%zu %s}\0A\00"
@.str.5 = [6 x i8] c"{%s}\0A\00"
define void @bufferedpackindexfd(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IROTH
%8 = load i32, i32* @S_IWOTH
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRUSR
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %6, i32 %13)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %75
18: ; preds = %1
%19 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = tail call i64 @malloc(i32 65536)
%25 = inttoptr i64 %24 to i8*
%26 = tail call %struct.dirent* @readdir(i32* %19)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %72, label %28
28: ; preds = %23, %69
%29 = phi %struct.dirent* [ %70, %69 ], [ %26, %23 ]
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 0
%31 = load i64, i64* %30
%32 = load i64, i64* @DT_DIR
%33 = icmp eq i64 %31, %32
br i1 %33, label %69, label %34
34: ; preds = %28
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 1
%36 = load i8*, i8** %35
%37 = tail call i64 @strlen(i8* dereferenceable(1) %36)
%38 = trunc i64 %37 to i32
%39 = add i32 %38, 7
%40 = tail call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
%42 = load i8*, i8** %35
%43 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %41, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @O_RDONLY
%45 = tail call i32 (i8*, i32, ...) @open(i8* %41, i32 %44)
%46 = tail call i64 @getfilesize_fd(i32 %45, i32* null, i32 0)
%47 = tail call i64 @strlen(i8* dereferenceable(1) %41)
%48 = shl i64 %47, 1
%49 = add i64 %48, 50
%50 = tail call i8* @llvm.stacksave()
%51 = alloca i8, i64 %49
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i64 %46, i8* %41)
%53 = call i64 @strlen(i8* %51)
%54 = call i64 @write(i32 %14, i8* %51, i64 %53)
%55 = icmp eq i64 %46, 0
br i1 %55, label %64, label %56
56: ; preds = %34
%57 = tail call i64 @read(i32 %45, i8* %25, i32 65536)
%58 = icmp eq i64 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %56, %59
%60 = phi i64 [ %62, %59 ], [ %57, %56 ]
%61 = tail call i64 @write(i32 %14, i8* %25, i64 %60)
%62 = tail call i64 @read(i32 %45, i8* %25, i32 65536)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %59
64: ; preds = %59, %56, %34
%65 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%66 = call i64 @strlen(i8* %51)
%67 = call i64 @write(i32 %14, i8* %51, i64 %66)
%68 = tail call i32 @close(i32 %45)
tail call void @llvm.stackrestore(i8* %50)
br label %69
69: ; preds = %64, %28
%70 = tail call %struct.dirent* @readdir(i32* %19)
%71 = icmp eq %struct.dirent* %70, null
br i1 %71, label %72, label %28
72: ; preds = %69, %23
%73 = tail call i32 @free(i8* %25)
%74 = tail call i32 @close(i32 %14)
br label %75
75: ; preds = %72, %16
ret void
}