#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 {
  int /*<<< orphan*/ *d_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(int /*<<< orphan*/ *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
scalar_t__ isdigit(int /*<<< orphan*/);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ quote(int /*<<< orphan*/ *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
void prep(char *outdir, int z, int x, int y, char *filetype, char *fname) {
  if (outdir == NULL) {
    return;
  }
  char path[strlen(outdir) + 12 + 12 + 12 + 5];
  sprintf(path, "%s", outdir);
  mkdir(path, 0777);
  int maxzoom = z, minzoom = z;
  DIR *d = opendir(outdir);
  if (d != NULL) {
    struct dirent *de;
    while ((de = readdir(d)) != NULL) {
      if (isdigit(*de->d_name)) {
        int n = atoi(de->d_name);
        if (n > maxzoom) {
          maxzoom = n;
        }
        if (n < minzoom) {
          minzoom = n;
        }
      }
    }
    closedir(d);
  }
  sprintf(path, "%s/metadata.json", outdir);
  FILE *fp = fopen(path, "w");
  if (fp == NULL) {
    perror(path);
    exit(EXIT_FAILURE);
  }
  fprintf(fp, "{\n");
  fprintf(fp, "\"name\": ");
  quote(fp, outdir);
  fprintf(fp, ",\n");
  fprintf(fp, "\"description\": ");
  quote(fp, fname);
  fprintf(fp, ",\n");
  fprintf(fp, "\"version\": 1,\n");
  fprintf(fp, "\"minzoom\": %d,\n", minzoom);
  fprintf(fp, "\"maxzoom\": %d,\n", maxzoom);
  fprintf(fp, "\"type\": \"overlay\",\n");
  if (strcmp(filetype, "pbf") == 0) {
    fprintf(fp, "\"json\": \"{");
    fprintf(
        fp,
        "\\\"vector_layers\\\": [ { \\\"id\\\": \\\"points\\\", "
        "\\\"description\\\": \\\"\\\", \\\"minzoom\\\": %d, \\\"maxzoom\\\": "
        "%d, \\\"fields\\\": {\\\"meta\\\": \\\"Number\\\" } }, { \\\"id\\\": "
        "\\\"lines\\\", \\\"description\\\": \\\"\\\", \\\"minzoom\\\": %d, "
        "\\\"maxzoom\\\": %d, \\\"fields\\\": {\\\"meta\\\": \\\"Number\\\" } "
        "} ]",
        minzoom, maxzoom, minzoom, maxzoom);
    fprintf(fp, "}\",\n");
  }
  fprintf(fp, "\"format\": \"%s\"\n", filetype);
  fprintf(fp, "}\n");
  fclose(fp);
  sprintf(path, "%s/%d", outdir, z);
  mkdir(path, 0777);
  sprintf(path, "%s/%d/%d", outdir, z, x);
  mkdir(path, 0777);
  sprintf(path, "%s/%d/%d/%d.%s", outdir, z, x, y, filetype);
  if (freopen(path, "wb", stdout) == NULL) {
    perror(path);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<prep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    122d <prep+0x2d>
jmp    157b <prep+0x37b>
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
add    $0x29,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x68(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdx
lea    0xf4e(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
mov    -0x68(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     131a <prep+0x11a>
jmp    12a5 <prep+0xa5>
mov    -0x48(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     1311 <prep+0x111>
mov    -0x50(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     130c <prep+0x10c>
mov    -0x50(%rbp),%rax
mov    (%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jle    12f5 <prep+0xf5>
mov    -0x54(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    1307 <prep+0x107>
mov    -0x54(%rbp),%eax
mov    %eax,-0x40(%rbp)
jmp    130c <prep+0x10c>
jmp    12a5 <prep+0xa5>
mov    -0x48(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xcd7(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
mov    -0x68(%rbp),%rdi
lea    0xcd6(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1366 <prep+0x166>
mov    -0x68(%rbp),%rdi
call   10f0 <perror@plt>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x60(%rbp),%rdi
lea    0xca2(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
lea    0xc93(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10d0 <quote@plt>
mov    -0x60(%rbp),%rdi
lea    0xccd(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
lea    0xc6b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10d0 <quote@plt>
mov    -0x60(%rbp),%rdi
lea    0xc9c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
lea    0xc4a(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x40(%rbp),%edx
lea    0xc44(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x3c(%rbp),%edx
lea    0xc3f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
lea    0xc3d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xc3f(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1486 <prep+0x286>
mov    -0x60(%rbp),%rdi
lea    0xc29(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x40(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
lea    0xc14(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
lea    0xd03(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xcf2(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
lea    0xcf0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x60(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xcd1(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
mov    -0x68(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xcac(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
mov    -0x68(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
mov    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x14(%rbp),%r9d
mov    -0x20(%rbp),%rax
lea    0xc82(%rip),%rsi
sub    $0x10,%rsp
mov    %rax,(%rsp)
mov    $0x0,%al
call   1110 <sprintf@plt>
mov    -0x68(%rbp),%rdi
add    $0x10,%rsp
mov    0x2a93(%rip),%rax
mov    (%rax),%edx
lea    0xc6a(%rip),%rsi
call   1080 <freopen@plt>
cmp    $0x0,%rax
jne    1574 <prep+0x374>
mov    -0x68(%rbp),%rdi
call   10f0 <perror@plt>
mov    0x2a73(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prep>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
test   %rdi,%rdi
je     155d <prep+0x33d>
mov    %esi,%r13d
mov    %rdi,%rbx
mov    %r9,-0x50(%rbp)
mov    %edx,-0x30(%rbp)
mov    %ecx,-0x34(%rbp)
mov    %r8,-0x58(%rbp)
call   1080 <strlen@plt>
mov    %rsp,-0x48(%rbp)
add    $0x29,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
mov    %rbx,-0x40(%rbp)
mov    %rbx,%rdi
call   1070 <opendir@plt>
mov    %r13d,%r12d
mov    %r13d,-0x2c(%rbp)
test   %rax,%rax
je     12ff <prep+0xdf>
mov    %rax,%r15
mov    %rax,%rdi
call   10d0 <readdir@plt>
mov    -0x2c(%rbp),%r13d
mov    %r13d,%r12d
test   %rax,%rax
je     12f7 <prep+0xd7>
mov    %rax,%rbx
mov    -0x2c(%rbp),%r12d
mov    %r12d,%r13d
jmp    12d0 <prep+0xb0>
xchg   %ax,%ax
mov    %r15,%rdi
call   10d0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12f7 <prep+0xd7>
mov    (%rbx),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     12c0 <prep+0xa0>
mov    (%rbx),%rdi
call   1110 <atoi@plt>
cmp    %r13d,%eax
cmovg  %eax,%r13d
cmp    %r12d,%eax
cmovl  %eax,%r12d
jmp    12c0 <prep+0xa0>
mov    %r15,%rdi
call   10a0 <closedir@plt>
lea    0xcfa(%rip),%rsi
mov    %r14,%rdi
mov    -0x40(%rbp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1120 <sprintf@plt>
lea    0xcf3(%rip),%rsi
mov    %r14,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     156c <prep+0x34c>
mov    %rax,%r15
lea    0xcda(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1140 <fwrite@plt>
lea    0xcc4(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1140 <fwrite@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10e0 <quote@plt>
lea    0xcf9(%rip),%rbx
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rdi
mov    %r15,%rcx
call   1140 <fwrite@plt>
lea    0xc8d(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1140 <fwrite@plt>
mov    %r15,%rdi
mov    -0x50(%rbp),%rsi
call   10e0 <quote@plt>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rdi
mov    %r15,%rcx
call   1140 <fwrite@plt>
lea    0xc63(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1140 <fwrite@plt>
lea    0xc59(%rip),%rsi
mov    %r15,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   10c0 <fprintf@plt>
lea    0xc55(%rip),%rsi
mov    %r15,%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   10c0 <fprintf@plt>
lea    0xc51(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1140 <fwrite@plt>
lea    0xc4c(%rip),%rsi
mov    -0x58(%rbp),%rbx
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
test   %rax,%rax
jne    1486 <prep+0x266>
lea    0xc38(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1140 <fwrite@plt>
lea    0xc2a(%rip),%rsi
mov    %r15,%rdi
mov    %r12d,%edx
mov    %r13d,%ecx
mov    %r12d,%r8d
mov    %r13d,%r9d
xor    %eax,%eax
call   10c0 <fprintf@plt>
lea    0xd0e(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1140 <fwrite@plt>
lea    0xcfa(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
lea    0xcf6(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1140 <fwrite@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
lea    0xcd8(%rip),%rsi
mov    %r14,%rdi
mov    -0x40(%rbp),%r12
mov    %r12,%rdx
mov    -0x2c(%rbp),%r15d
mov    %r15d,%ecx
xor    %eax,%eax
call   1120 <sprintf@plt>
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
lea    0xcb2(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %rbx,%r13
mov    -0x30(%rbp),%ebx
mov    %ebx,%r8d
xor    %eax,%eax
call   1120 <sprintf@plt>
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
sub    $0x8,%rsp
lea    0xc8a(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %ebx,%r8d
mov    -0x34(%rbp),%r9d
xor    %eax,%eax
push   %r13
call   1120 <sprintf@plt>
add    $0x10,%rsp
mov    0x2a95(%rip),%rax
mov    (%rax),%edx
lea    0xc6c(%rip),%rsi
mov    %r14,%rdi
call   1090 <freopen@plt>
test   %rax,%rax
je     156c <prep+0x34c>
mov    -0x48(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1100 <perror@plt>
mov    0x2a65(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32* }
@.str = [3 x i8] c"%s\00"
@.str.1 = [17 x i8] c"%s/metadata.json\00"
@.str.2 = [2 x i8] c"w\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"{\0A\00"
@.str.4 = [9 x i8] c"\22name\22: \00"
@.str.5 = [3 x i8] c",\0A\00"
@.str.6 = [16 x i8] c"\22description\22: \00"
@.str.7 = [15 x i8] c"\22version\22: 1,\0A\00"
@.str.8 = [16 x i8] c"\22minzoom\22: %d,\0A\00"
@.str.9 = [16 x i8] c"\22maxzoom\22: %d,\0A\00"
@.str.10 = [20 x i8] c"\22type\22: \22overlay\22,\0A\00"
@.str.11 = [4 x i8] c"pbf\00"
@.str.12 = [11 x i8] c"\22json\22: \22{\00"
@.str.13 = [257 x i8] c"\\\22vector_layers\\\22: [ { \\\22id\\\22: \\\22points\\\22, \\\22description\\\22: \\\22\\\22, \\\22minzoom\\\22: %d, \\\22maxzoom\\\22: %d, \\\22fields\\\22: {\\\22meta\\\22: \\\22Number\\\22 } }, { \\\22id\\\22: \\\22lines\\\22, \\\22description\\\22: \\\22\\\22, \\\22minzoom\\\22: %d, \\\22maxzoom\\\22: %d, \\\22fields\\\22: {\\\22meta\\\22: \\\22Number\\\22 } } ]\00"
@.str.14 = [5 x i8] c"}\22,\0A\00"
@.str.15 = [16 x i8] c"\22format\22: \22%s\22\0A\00"
@.str.16 = [3 x i8] c"}\0A\00"
@.str.17 = [6 x i8] c"%s/%d\00"
@.str.18 = [9 x i8] c"%s/%d/%d\00"
@.str.19 = [15 x i8] c"%s/%d/%d/%d.%s\00"
@.str.20 = [3 x i8] c"wb\00"
@stdout = global i32 0
define void @prep(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca %struct.dirent*
%19 = alloca i32
%20 = alloca i32*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%21 = load i8*, i8** %7
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %6
br label %159
24: ; preds = %6
%25 = load i8*, i8** %7
%26 = call i32 @strlen(i8* %25)
%27 = add nsw i32 %26, 12
%28 = add nsw i32 %27, 12
%29 = add nsw i32 %28, 12
%30 = add nsw i32 %29, 5
%31 = zext i32 %30 to i64
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %13
%33 = alloca i8, i64 %31
store i64 %31, i64* %14
%34 = load i8*, i8** %7
%35 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = call i32 @mkdir(i8* %33, i32 511)
%37 = load i32, i32* %8
store i32 %37, i32* %15
%38 = load i32, i32* %8
store i32 %38, i32* %16
%39 = load i8*, i8** %7
%40 = call i32* @opendir(i8* %39)
store i32* %40, i32** %17
%41 = load i32*, i32** %17
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %76
43: ; preds = %24
br label %44
44: ; preds = %72, %43
%45 = load i32*, i32** %17
%46 = call %struct.dirent* @readdir(i32* %45)
store %struct.dirent* %46, %struct.dirent** %18
%47 = icmp ne %struct.dirent* %46, null
br i1 %47, label %48, label %73
48: ; preds = %44
%49 = load %struct.dirent*, %struct.dirent** %18
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 0
%51 = load i32*, i32** %50
%52 = load i32, i32* %51
%53 = call i64 @isdigit(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %72
55: ; preds = %48
%56 = load %struct.dirent*, %struct.dirent** %18
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %56, i32 0, i32 0
%58 = load i32*, i32** %57
%59 = call i32 @atoi(i32* %58)
store i32 %59, i32* %19
%60 = load i32, i32* %19
%61 = load i32, i32* %15
%62 = icmp sgt i32 %60, %61
br i1 %62, label %63, label %65
63: ; preds = %55
%64 = load i32, i32* %19
store i32 %64, i32* %15
br label %65
65: ; preds = %63, %55
%66 = load i32, i32* %19
%67 = load i32, i32* %16
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %71
69: ; preds = %65
%70 = load i32, i32* %19
store i32 %70, i32* %16
br label %71
71: ; preds = %69, %65
br label %72
72: ; preds = %71, %48
br label %44
73: ; preds = %44
%74 = load i32*, i32** %17
%75 = call i32 @closedir(i32* %74)
br label %76
76: ; preds = %73, %24
%77 = load i8*, i8** %7
%78 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %77)
%79 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %79, i32** %20
%80 = load i32*, i32** %20
%81 = icmp eq i32* %80, null
br i1 %81, label %82, label %86
82: ; preds = %76
%83 = call i32 @perror(i8* %33)
%84 = load i32, i32* @EXIT_FAILURE
%85 = call i32 @exit(i32 %84)
unreachable
86: ; preds = %76
%87 = load i32*, i32** %20
%88 = call i32 (i32*, i8*, ...) @fprintf(i32* %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%89 = load i32*, i32** %20
%90 = call i32 (i32*, i8*, ...) @fprintf(i32* %89, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%91 = load i32*, i32** %20
%92 = load i8*, i8** %7
%93 = call i32 @quote(i32* %91, i8* %92)
%94 = load i32*, i32** %20
%95 = call i32 (i32*, i8*, ...) @fprintf(i32* %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%96 = load i32*, i32** %20
%97 = call i32 (i32*, i8*, ...) @fprintf(i32* %96, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%98 = load i32*, i32** %20
%99 = load i8*, i8** %12
%100 = call i32 @quote(i32* %98, i8* %99)
%101 = load i32*, i32** %20
%102 = call i32 (i32*, i8*, ...) @fprintf(i32* %101, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%103 = load i32*, i32** %20
%104 = call i32 (i32*, i8*, ...) @fprintf(i32* %103, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%105 = load i32*, i32** %20
%106 = load i32, i32* %16
%107 = call i32 (i32*, i8*, ...) @fprintf(i32* %105, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %106)
%108 = load i32*, i32** %20
%109 = load i32, i32* %15
%110 = call i32 (i32*, i8*, ...) @fprintf(i32* %108, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %109)
%111 = load i32*, i32** %20
%112 = call i32 (i32*, i8*, ...) @fprintf(i32* %111, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
%113 = load i8*, i8** %11
%114 = call i64 @strcmp(i8* %113, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%115 = icmp eq i64 %114, 0
br i1 %115, label %116, label %127
116: ; preds = %86
%117 = load i32*, i32** %20
%118 = call i32 (i32*, i8*, ...) @fprintf(i32* %117, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0))
%119 = load i32*, i32** %20
%120 = load i32, i32* %16
%121 = load i32, i32* %15
%122 = load i32, i32* %16
%123 = load i32, i32* %15
%124 = call i32 (i32*, i8*, ...) @fprintf(i32* %119, i8* getelementptr inbounds ([257 x i8], [257 x i8]* @.str.13, i64 0, i64 0), i32 %120, i32 %121, i32 %122, i32 %123)
%125 = load i32*, i32** %20
%126 = call i32 (i32*, i8*, ...) @fprintf(i32* %125, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %127
127: ; preds = %116, %86
%128 = load i32*, i32** %20
%129 = load i8*, i8** %11
%130 = call i32 (i32*, i8*, ...) @fprintf(i32* %128, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.15, i64 0, i64 0), i8* %129)
%131 = load i32*, i32** %20
%132 = call i32 (i32*, i8*, ...) @fprintf(i32* %131, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
%133 = load i32*, i32** %20
%134 = call i32 @fclose(i32* %133)
%135 = load i8*, i8** %7
%136 = load i32, i32* %8
%137 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0), i8* %135, i32 %136)
%138 = call i32 @mkdir(i8* %33, i32 511)
%139 = load i8*, i8** %7
%140 = load i32, i32* %8
%141 = load i32, i32* %9
%142 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i64 0, i64 0), i8* %139, i32 %140, i32 %141)
%143 = call i32 @mkdir(i8* %33, i32 511)
%144 = load i8*, i8** %7
%145 = load i32, i32* %8
%146 = load i32, i32* %9
%147 = load i32, i32* %10
%148 = load i8*, i8** %11
%149 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.19, i64 0, i64 0), i8* %144, i32 %145, i32 %146, i32 %147, i8* %148)
%150 = load i32, i32* @stdout
%151 = call i32* @freopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0), i32 %150)
%152 = icmp eq i32* %151, null
br i1 %152, label %153, label %157
153: ; preds = %127
%154 = call i32 @perror(i8* %33)
%155 = load i32, i32* @EXIT_FAILURE
%156 = call i32 @exit(i32 %155)
unreachable
157: ; preds = %127
%158 = load i8*, i8** %13
br label %159
159: ; preds = %157, %23
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32* }
@.str.1 = [17 x i8] c"%s/metadata.json\00"
@.str.2 = [2 x i8] c"w\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"{\0A\00"
@.str.4 = [9 x i8] c"\22name\22: \00"
@.str.5 = [3 x i8] c",\0A\00"
@.str.6 = [16 x i8] c"\22description\22: \00"
@.str.7 = [15 x i8] c"\22version\22: 1,\0A\00"
@.str.8 = [16 x i8] c"\22minzoom\22: %d,\0A\00"
@.str.9 = [16 x i8] c"\22maxzoom\22: %d,\0A\00"
@.str.10 = [20 x i8] c"\22type\22: \22overlay\22,\0A\00"
@.str.11 = [4 x i8] c"pbf\00"
@.str.12 = [11 x i8] c"\22json\22: \22{\00"
@.str.13 = [257 x i8] c"\\\22vector_layers\\\22: [ { \\\22id\\\22: \\\22points\\\22, \\\22description\\\22: \\\22\\\22, \\\22minzoom\\\22: %d, \\\22maxzoom\\\22: %d, \\\22fields\\\22: {\\\22meta\\\22: \\\22Number\\\22 } }, { \\\22id\\\22: \\\22lines\\\22, \\\22description\\\22: \\\22\\\22, \\\22minzoom\\\22: %d, \\\22maxzoom\\\22: %d, \\\22fields\\\22: {\\\22meta\\\22: \\\22Number\\\22 } } ]\00"
@.str.14 = [5 x i8] c"}\22,\0A\00"
@.str.15 = [16 x i8] c"\22format\22: \22%s\22\0A\00"
@.str.16 = [3 x i8] c"}\0A\00"
@.str.17 = [6 x i8] c"%s/%d\00"
@.str.18 = [9 x i8] c"%s/%d/%d\00"
@.str.19 = [15 x i8] c"%s/%d/%d/%d.%s\00"
@.str.20 = [3 x i8] c"wb\00"
@stdout = global i32 0
define void @prep(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4, i8* %5) {
%7 = icmp eq i8* %0, null
br i1 %7, label %91, label %8
8: ; preds = %6
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, 41
%11 = zext i32 %10 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = call i8* @strcpy(i8* %13, i8* %0)
%15 = call i32 @mkdir(i8* %13, i32 511)
%16 = call i32* @opendir(i8* %0)
%17 = icmp eq i32* %16, null
br i1 %17, label %46, label %18
18: ; preds = %8
%19 = call %struct.dirent* @readdir(i32* %16)
%20 = icmp eq %struct.dirent* %19, null
br i1 %20, label %42, label %21
21: ; preds = %18, %37
%22 = phi %struct.dirent* [ %40, %37 ], [ %19, %18 ]
%23 = phi i32 [ %39, %37 ], [ %1, %18 ]
%24 = phi i32 [ %38, %37 ], [ %1, %18 ]
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i64 0, i32 0
%26 = load i32*, i32** %25
%27 = load i32, i32* %26
%28 = call i64 @isdigit(i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %21
%31 = load i32*, i32** %25
%32 = call i32 @atoi(i32* %31)
%33 = icmp sgt i32 %32, %23
%34 = select i1 %33, i32 %32, i32 %23
%35 = icmp slt i32 %32, %24
%36 = select i1 %35, i32 %32, i32 %24
br label %37
37: ; preds = %30, %21
%38 = phi i32 [ %36, %30 ], [ %24, %21 ]
%39 = phi i32 [ %34, %30 ], [ %23, %21 ]
%40 = call %struct.dirent* @readdir(i32* %16)
%41 = icmp eq %struct.dirent* %40, null
br i1 %41, label %42, label %21
42: ; preds = %37, %18
%43 = phi i32 [ %1, %18 ], [ %38, %37 ]
%44 = phi i32 [ %1, %18 ], [ %39, %37 ]
%45 = call i32 @closedir(i32* %16)
br label %46
46: ; preds = %42, %8
%47 = phi i32 [ %43, %42 ], [ %1, %8 ]
%48 = phi i32 [ %44, %42 ], [ %1, %8 ]
%49 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%50 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %56
52: ; preds = %46
%53 = call i32 @perror(i8* %13)
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %46
%57 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %50)
%58 = call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i64 8, i64 1, i32* %50)
%59 = call i32 @quote(i32* %50, i8* %0)
%60 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %50)
%61 = call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i64 15, i64 1, i32* %50)
%62 = call i32 @quote(i32* %50, i8* %5)
%63 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %50)
%64 = call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i64 14, i64 1, i32* %50)
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %47)
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %48)
%67 = call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i64 19, i64 1, i32* %50)
%68 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %56
%71 = call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i64 10, i64 1, i32* %50)
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([257 x i8], [257 x i8]* @.str.13, i64 0, i64 0), i32 %47, i32 %48, i32 %47, i32 %48)
%73 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i64 4, i64 1, i32* %50)
br label %74
74: ; preds = %70, %56
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.15, i64 0, i64 0), i8* %4)
%76 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0), i64 2, i64 1, i32* %50)
%77 = call i32 @fclose(i32* %50)
%78 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0), i8* %0, i32 %1)
%79 = call i32 @mkdir(i8* %13, i32 511)
%80 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i64 0, i64 0), i8* %0, i32 %1, i32 %2)
%81 = call i32 @mkdir(i8* %13, i32 511)
%82 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.19, i64 0, i64 0), i8* %0, i32 %1, i32 %2, i32 %3, i8* %4)
%83 = load i32, i32* @stdout
%84 = call i32* @freopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.20, i64 0, i64 0), i32 %83)
%85 = icmp eq i32* %84, null
br i1 %85, label %86, label %90
86: ; preds = %74
%87 = call i32 @perror(i8* %13)
%88 = load i32, i32* @EXIT_FAILURE
%89 = call i32 @exit(i32 %88)
unreachable
90: ; preds = %74
br label %91
91: ; preds = %6, %90
ret void
}