#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ download_file(char *, char *, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *gethome();
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ *mkdtemp(char *);
scalar_t__ rename(char *, char *);
scalar_t__ rm(char *, int /*<<< orphan*/);
scalar_t__ sstrncat(char *, size_t *, int, char const *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int strlen(char const *);
scalar_t__ unzip(char *, char *);
scalar_t__ update_localdate();
int update_localdb(int verbose) {
  struct stat s;
  char tmp[512];
  char outpath[512];
  char outfile[512];
  char outhome[512];
  char const *homedir;
  size_t outlen;
  outlen = 0;
  if (sstrncat(outfile, &outlen, 512, "/tmp/tldrXXXXXX",
               (sizeof("/tmp/tldrXXXXXX") - 1)))
    return 1;
  if (mkdtemp(outfile) == NULL) {
    fprintf(stderr, "Error: Creating Directory: %s\n", outfile);
    return 1;
  }
  outlen = 0;
  if (sstrncat(outpath, &outlen, 512, outfile, (sizeof("/tmp/tldrXXXXXX") - 1)))
    return 1;
  outlen = (sizeof("/tmp/tldrXXXXXX") - 1);
  if (sstrncat(outfile, &outlen, 512, "/master.zip",
               (sizeof("/master.zip") - 1)))
    return 1;
  if (download_file("https://github.com/tldr-pages/tldr/archive/master.zip",
                    outfile, verbose)) {
    fprintf(stderr, "Error: Downloading File: %s\n",
            "https://github.com/tldr-pages/tldr/archive/master.zip");
    return 1;
  }
  if (unzip(outfile, outpath)) {
    rm(outpath, 0);
    return 1;
  }
  outlen = 0;
  if (sstrncat(tmp, &outlen, 512, outpath, strlen(outpath)))
    return 1;
  if (sstrncat(tmp, &outlen, 512, "/tldr-master", (sizeof("/tldr-master") - 1)))
    return 1;
  homedir = gethome();
  if (homedir == NULL) {
    fprintf(stderr, "Error: HOME not existant\n");
    return 1;
  }
  outlen = 0;
  if (sstrncat(outhome, &outlen, 512, homedir, strlen(homedir))) {
    return 1;
  }
  if (sstrncat(outhome, &outlen, 512, "/.tldrc", (sizeof("/.tldrc") - 1))) {
    return 1;
  }
  if (mkdir(outhome, 0755) > 0 && errno != EEXIST) {
    fprintf(stderr, "Error: Could Not Create Directory: %s\n", outhome);
    rm(outpath, 0);
    return 1;
  }
  if (sstrncat(outhome, &outlen, 512, "/tldr-master",
               (sizeof("/tldr-master") - 1)))
    return 1;
  if (sstrncat(outhome, &outlen, 512, "/", 1))
    return 1;
  if ((stat(outhome, &s) == 0) && (S_ISDIR(s.st_mode))) {
    if (rm(outhome, 0)) {
      fprintf(stderr, "Error: Could Not Remove: %s\n", outhome);
      return 1;
    }
  }
  if (rename(tmp, outhome)) {
    fprintf(stderr, "Error: Could Not Rename: %s to %s\n", tmp, outhome);
    rm(outpath, 0);
    return 1;
  }
  if (rm(outpath, 0)) {
    fprintf(stderr, "Error: Could Not Remove: %s\n", outpath);
    return 1;
  }
  if (update_localdate()) {
    fprintf(stderr, "Error: Could not update last updated date\n");
    return 1;
  }
  fprintf(stdout, "Successfully updated local database\n");
  return 0;
}


x86 assembly (clang, -O0):
<update_localdb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %edi,-0x8(%rbp)
movq   $0x0,-0x820(%rbp)
lea    -0x610(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x200,%edx
lea    0xdfd(%rip),%rcx
mov    $0xf,%r8d
call   1090 <sstrncat@plt>
cmp    $0x0,%rax
je     1224 <update_localdb+0x54>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x610(%rbp),%rdi
call   10c0 <mkdtemp@plt>
cmp    $0x0,%rax
jne    1264 <update_localdb+0x94>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    -0x610(%rbp),%rdx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
movq   $0x0,-0x820(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x610(%rbp),%rcx
lea    -0x820(%rbp),%rsi
mov    $0x200,%edx
mov    $0xf,%r8d
call   1090 <sstrncat@plt>
cmp    $0x0,%rax
je     12aa <update_localdb+0xda>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
movq   $0xf,-0x820(%rbp)
lea    -0x610(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x200,%edx
lea    0xd8a(%rip),%rcx
mov    $0xb,%r8d
call   1090 <sstrncat@plt>
cmp    $0x0,%rax
je     12f0 <update_localdb+0x120>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x610(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xd2e(%rip),%rdi
call   1060 <download_file@plt>
cmp    $0x0,%rax
je     133a <update_localdb+0x16a>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
lea    0xd45(%rip),%rsi
lea    0xd08(%rip),%rdx
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x610(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1080 <unzip@plt>
cmp    $0x0,%rax
je     1371 <update_localdb+0x1a1>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
call   1030 <rm@plt>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
movq   $0x0,-0x820(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x830(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x828(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x830(%rbp),%rdi
mov    -0x828(%rbp),%rcx
mov    %eax,%r8d
lea    -0x820(%rbp),%rsi
mov    $0x200,%edx
call   1090 <sstrncat@plt>
cmp    $0x0,%rax
je     13dc <update_localdb+0x20c>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x210(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x200,%edx
lea    0xc8c(%rip),%rcx
mov    $0xc,%r8d
call   1090 <sstrncat@plt>
cmp    $0x0,%rax
je     1417 <update_localdb+0x247>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
mov    $0x0,%al
call   10f0 <gethome@plt>
mov    %rax,-0x818(%rbp)
cmpq   $0x0,-0x818(%rbp)
jne    1456 <update_localdb+0x286>
mov    0x2b9e(%rip),%rax
mov    (%rax),%edi
lea    0xc4c(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
movq   $0x0,-0x820(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    -0x818(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    -0x818(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x840(%rbp),%rdi
mov    -0x838(%rbp),%rcx
mov    %eax,%r8d
lea    -0x820(%rbp),%rsi
mov    $0x200,%edx
call   1090 <sstrncat@plt>
cmp    $0x0,%rax
je     14c1 <update_localdb+0x2f1>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x810(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x200,%edx
lea    0xbce(%rip),%rcx
mov    $0x7,%r8d
call   1090 <sstrncat@plt>
cmp    $0x0,%rax
je     14fc <update_localdb+0x32c>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x810(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jle    1569 <update_localdb+0x399>
mov    0x2ab2(%rip),%rax
mov    (%rax),%rax
mov    0x2ab8(%rip),%rcx
cmp    (%rcx),%rax
je     1569 <update_localdb+0x399>
mov    0x2aa0(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rdx
lea    0xb69(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
call   1030 <rm@plt>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x810(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x200,%edx
lea    0xaff(%rip),%rcx
mov    $0xc,%r8d
call   1090 <sstrncat@plt>
cmp    $0x0,%rax
je     15a4 <update_localdb+0x3d4>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x810(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x200,%edx
lea    0xb1a(%rip),%rcx
mov    $0x1,%r8d
call   1090 <sstrncat@plt>
cmp    $0x0,%rax
je     15df <update_localdb+0x40f>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x810(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
jne    1652 <update_localdb+0x482>
mov    -0x10(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1652 <update_localdb+0x482>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
call   1030 <rm@plt>
cmp    $0x0,%rax
je     164d <update_localdb+0x47d>
mov    0x29ae(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rdx
lea    0xaa0(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
jmp    1652 <update_localdb+0x482>
lea    -0x210(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   10e0 <rename@plt>
cmp    $0x0,%rax
je     16ae <update_localdb+0x4de>
mov    0x2962(%rip),%rax
mov    (%rax),%edi
lea    -0x210(%rbp),%rdx
lea    -0x810(%rbp),%rcx
lea    0xa6a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
call   1030 <rm@plt>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
call   1030 <rm@plt>
cmp    $0x0,%rax
je     16f0 <update_localdb+0x520>
mov    0x290b(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0x9fd(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
mov    $0x0,%al
call   10d0 <update_localdate@plt>
cmp    $0x0,%rax
je     1724 <update_localdb+0x554>
mov    0x28d0(%rip),%rax
mov    (%rax),%edi
lea    0xa09(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1742 <update_localdb+0x572>
mov    0x289d(%rip),%rax
mov    (%rax),%edi
lea    0xa11(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_localdb>:
push   %rbp
push   %rbx
sub    $0x818,%rsp
mov    %edi,%ebp
movq   $0x0,(%rsp)
lea    0xe16(%rip),%rcx
lea    0x410(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x200,%edx
mov    $0xf,%r8d
call   1090 <sstrncat@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    12df <update_localdb+0x10f>
lea    0x410(%rsp),%rdi
call   10c0 <mkdtemp@plt>
test   %rax,%rax
je     12c0 <update_localdb+0xf0>
movq   $0x0,(%rsp)
lea    0x210(%rsp),%rdi
mov    %rsp,%rsi
lea    0x410(%rsp),%rcx
mov    $0x200,%edx
mov    $0xf,%r8d
call   1090 <sstrncat@plt>
test   %rax,%rax
jne    12df <update_localdb+0x10f>
movq   $0xf,(%rsp)
lea    0xded(%rip),%rcx
lea    0x410(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x200,%edx
mov    $0xb,%r8d
call   1090 <sstrncat@plt>
test   %rax,%rax
jne    12df <update_localdb+0x10f>
lea    0xd9c(%rip),%rdi
lea    0x410(%rsp),%rsi
mov    %ebp,%edx
call   1060 <download_file@plt>
test   %rax,%rax
je     12eb <update_localdb+0x11b>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
lea    0xd71(%rip),%rdx
jmp    12d8 <update_localdb+0x108>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
lea    0x410(%rsp),%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %ebx,%eax
add    $0x818,%rsp
pop    %rbx
pop    %rbp
ret
lea    0x410(%rsp),%rdi
lea    0x210(%rsp),%rsi
call   1080 <unzip@plt>
test   %rax,%rax
je     1316 <update_localdb+0x146>
lea    0x210(%rsp),%rdi
xor    %esi,%esi
call   1030 <rm@plt>
jmp    12df <update_localdb+0x10f>
movq   $0x0,(%rsp)
lea    0x210(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x610(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x200,%edx
mov    %rbp,%rcx
mov    %eax,%r8d
call   1090 <sstrncat@plt>
test   %rax,%rax
jne    12df <update_localdb+0x10f>
lea    0xd2d(%rip),%rcx
lea    0x610(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x200,%edx
mov    $0xc,%r8d
call   1090 <sstrncat@plt>
test   %rax,%rax
jne    12df <update_localdb+0x10f>
xor    %eax,%eax
call   10f0 <gethome@plt>
test   %rax,%rax
je     14c4 <update_localdb+0x2f4>
mov    %rax,%rbp
movq   $0x0,(%rsp)
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x200,%edx
mov    %rbp,%rcx
mov    %eax,%r8d
call   1090 <sstrncat@plt>
test   %rax,%rax
jne    12df <update_localdb+0x10f>
lea    0xce5(%rip),%rcx
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x200,%edx
mov    $0x7,%r8d
call   1090 <sstrncat@plt>
test   %rax,%rax
jne    12df <update_localdb+0x10f>
lea    0x10(%rsp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
jle    1413 <update_localdb+0x243>
mov    0x2bd0(%rip),%rax
mov    (%rax),%rax
mov    0x2bd6(%rip),%rcx
cmp    (%rcx),%rax
jne    14e0 <update_localdb+0x310>
lea    0xc68(%rip),%rcx
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x200,%edx
mov    $0xc,%r8d
call   1090 <sstrncat@plt>
test   %rax,%rax
jne    12df <update_localdb+0x10f>
lea    0xc96(%rip),%rcx
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x1,%ebx
mov    $0x200,%edx
mov    $0x1,%r8d
call   1090 <sstrncat@plt>
test   %rax,%rax
jne    12df <update_localdb+0x10f>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
je     1501 <update_localdb+0x331>
lea    0x610(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10e0 <rename@plt>
test   %rax,%rax
je     1542 <update_localdb+0x372>
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
lea    0xc4c(%rip),%rsi
lea    0x610(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1305 <update_localdb+0x135>
mov    0x2b0d(%rip),%rax
mov    (%rax),%edi
lea    0xbbb(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    12df <update_localdb+0x10f>
mov    0x2af1(%rip),%rax
mov    (%rax),%edi
lea    0xbc1(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1305 <update_localdb+0x135>
mov    0x8(%rsp),%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     1480 <update_localdb+0x2b0>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <rm@plt>
test   %rax,%rax
je     1480 <update_localdb+0x2b0>
mov    0x2aa9(%rip),%rax
mov    (%rax),%edi
lea    0xba2(%rip),%rsi
lea    0x10(%rsp),%rdx
jmp    12d8 <update_localdb+0x108>
lea    0x210(%rsp),%rdi
xor    %esi,%esi
call   1030 <rm@plt>
test   %rax,%rax
je     1573 <update_localdb+0x3a3>
mov    0x2a7b(%rip),%rax
mov    (%rax),%edi
lea    0xb74(%rip),%rsi
lea    0x210(%rsp),%rdx
jmp    12d8 <update_localdb+0x108>
xor    %eax,%eax
call   10d0 <update_localdate@plt>
test   %rax,%rax
je     1594 <update_localdb+0x3c4>
mov    0x2a52(%rip),%rax
mov    (%rax),%edi
lea    0xb8b(%rip),%rsi
jmp    14d4 <update_localdb+0x304>
mov    0x2a2d(%rip),%rax
mov    (%rax),%edi
lea    0xba1(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %ebx,%ebx
jmp    12df <update_localdb+0x10f>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [16 x i8] c"/tmp/tldrXXXXXX\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Error: Creating Directory: %s\0A\00"
@.str.2 = [12 x i8] c"/master.zip\00"
@.str.3 = [54 x i8] c"https://github.com/tldr-pages/tldr/archive/master.zip\00"
@.str.4 = [29 x i8] c"Error: Downloading File: %s\0A\00"
@.str.5 = [13 x i8] c"/tldr-master\00"
@.str.6 = [26 x i8] c"Error: HOME not existant\0A\00"
@.str.7 = [8 x i8] c"/.tldrc\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.8 = [39 x i8] c"Error: Could Not Create Directory: %s\0A\00"
@.str.9 = [2 x i8] c"/\00"
@.str.10 = [29 x i8] c"Error: Could Not Remove: %s\0A\00"
@.str.11 = [35 x i8] c"Error: Could Not Rename: %s to %s\0A\00"
@.str.12 = [43 x i8] c"Error: Could not update last updated date\0A\00"
@stdout = global i32 0
@.str.13 = [37 x i8] c"Successfully updated local database\0A\00"
define i32 @update_localdb(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca [512 x i8]
%9 = alloca i8*
%10 = alloca i64
store i32 %0, i32* %3
store i64 0, i64* %10
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%12 = call i64 @sstrncat(i8* %11, i64* %10, i32 512, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 15)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 1, i32* %2
br label %154
15: ; preds = %1
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%17 = call i32* @mkdtemp(i8* %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 1, i32* %2
br label %154
23: ; preds = %15
store i64 0, i64* %10
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%26 = call i64 @sstrncat(i8* %24, i64* %10, i32 512, i8* %25, i32 15)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 1, i32* %2
br label %154
29: ; preds = %23
store i64 15, i64* %10
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%31 = call i64 @sstrncat(i8* %30, i64* %10, i32 512, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 1, i32* %2
br label %154
34: ; preds = %29
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%36 = load i32, i32* %3
%37 = call i64 @download_file(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
br label %154
42: ; preds = %34
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%45 = call i64 @unzip(i8* %43, i8* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%49 = call i64 @rm(i8* %48, i32 0)
store i32 1, i32* %2
br label %154
50: ; preds = %42
store i64 0, i64* %10
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%54 = call i32 @strlen(i8* %53)
%55 = call i64 @sstrncat(i8* %51, i64* %10, i32 512, i8* %52, i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %50
store i32 1, i32* %2
br label %154
58: ; preds = %50
%59 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%60 = call i64 @sstrncat(i8* %59, i64* %10, i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %58
store i32 1, i32* %2
br label %154
63: ; preds = %58
%64 = call i8* (...) @gethome()
store i8* %64, i8** %9
%65 = load i8*, i8** %9
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %2
br label %154
70: ; preds = %63
store i64 0, i64* %10
%71 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%72 = load i8*, i8** %9
%73 = load i8*, i8** %9
%74 = call i32 @strlen(i8* %73)
%75 = call i64 @sstrncat(i8* %71, i64* %10, i32 512, i8* %72, i32 %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %70
store i32 1, i32* %2
br label %154
78: ; preds = %70
%79 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%80 = call i64 @sstrncat(i8* %79, i64* %10, i32 512, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 7)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %78
store i32 1, i32* %2
br label %154
83: ; preds = %78
%84 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%85 = call i64 @mkdir(i8* %84, i32 493)
%86 = icmp sgt i64 %85, 0
br i1 %86, label %87, label %97
87: ; preds = %83
%88 = load i64, i64* @errno
%89 = load i64, i64* @EEXIST
%90 = icmp ne i64 %88, %89
br i1 %90, label %91, label %97
91: ; preds = %87
%92 = load i32, i32* @stderr
%93 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %93)
%95 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%96 = call i64 @rm(i8* %95, i32 0)
store i32 1, i32* %2
br label %154
97: ; preds = %87, %83
%98 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%99 = call i64 @sstrncat(i8* %98, i64* %10, i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%100 = icmp ne i64 %99, 0
br i1 %100, label %101, label %102
101: ; preds = %97
store i32 1, i32* %2
br label %154
102: ; preds = %97
%103 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%104 = call i64 @sstrncat(i8* %103, i64* %10, i32 512, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 1)
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %107
106: ; preds = %102
store i32 1, i32* %2
br label %154
107: ; preds = %102
%108 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%109 = call i64 @stat(i8* %108, %struct.stat* %4)
%110 = icmp eq i64 %109, 0
br i1 %110, label %111, label %125
111: ; preds = %107
%112 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%113 = load i32, i32* %112
%114 = call i64 @S_ISDIR(i32 %113)
%115 = icmp ne i64 %114, 0
br i1 %115, label %116, label %125
116: ; preds = %111
%117 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%118 = call i64 @rm(i8* %117, i32 0)
%119 = icmp ne i64 %118, 0
br i1 %119, label %120, label %124
120: ; preds = %116
%121 = load i32, i32* @stderr
%122 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %122)
store i32 1, i32* %2
br label %154
124: ; preds = %116
br label %125
125: ; preds = %124, %111, %107
%126 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%127 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%128 = call i64 @rename(i8* %126, i8* %127)
%129 = icmp ne i64 %128, 0
br i1 %129, label %130, label %137
130: ; preds = %125
%131 = load i32, i32* @stderr
%132 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%133 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i8* %132, i8* %133)
%135 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%136 = call i64 @rm(i8* %135, i32 0)
store i32 1, i32* %2
br label %154
137: ; preds = %125
%138 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%139 = call i64 @rm(i8* %138, i32 0)
%140 = icmp ne i64 %139, 0
br i1 %140, label %141, label %145
141: ; preds = %137
%142 = load i32, i32* @stderr
%143 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %142, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %143)
store i32 1, i32* %2
br label %154
145: ; preds = %137
%146 = call i64 (...) @update_localdate()
%147 = icmp ne i64 %146, 0
br i1 %147, label %148, label %151
148: ; preds = %145
%149 = load i32, i32* @stderr
%150 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %2
br label %154
151: ; preds = %145
%152 = load i32, i32* @stdout
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %2
br label %154
154: ; preds = %151, %148, %141, %130, %120, %106, %101, %91, %82, %77, %67, %62, %57, %47, %39, %33, %28, %19, %14
%155 = load i32, i32* %2
ret i32 %155
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [16 x i8] c"/tmp/tldrXXXXXX\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Error: Creating Directory: %s\0A\00"
@.str.2 = [12 x i8] c"/master.zip\00"
@.str.3 = [54 x i8] c"https://github.com/tldr-pages/tldr/archive/master.zip\00"
@.str.4 = [29 x i8] c"Error: Downloading File: %s\0A\00"
@.str.5 = [13 x i8] c"/tldr-master\00"
@.str.6 = [26 x i8] c"Error: HOME not existant\0A\00"
@.str.7 = [8 x i8] c"/.tldrc\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.8 = [39 x i8] c"Error: Could Not Create Directory: %s\0A\00"
@.str.9 = [2 x i8] c"/\00"
@.str.10 = [29 x i8] c"Error: Could Not Remove: %s\0A\00"
@.str.11 = [35 x i8] c"Error: Could Not Rename: %s to %s\0A\00"
@.str.12 = [43 x i8] c"Error: Could not update last updated date\0A\00"
@stdout = global i32 0
@.str.13 = [37 x i8] c"Successfully updated local database\0A\00"
define i32 @update_localdb(i32 %0) {
%2 = alloca %struct.stat
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca i64
%8 = bitcast %struct.stat* %2 to i8*
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%13 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%14 = call i64 @sstrncat(i8* %11, i64* %7, i32 512, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 15)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %112
16: ; preds = %1
%17 = call i32* @mkdtemp(i8* %11)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %112
22: ; preds = %16
store i64 0, i64* %7
%23 = call i64 @sstrncat(i8* %10, i64* %7, i32 512, i8* %11, i32 15)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %112
25: ; preds = %22
store i64 15, i64* %7
%26 = call i64 @sstrncat(i8* %11, i64* %7, i32 512, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %112
28: ; preds = %25
%29 = call i64 @download_file(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32 %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
br label %112
34: ; preds = %28
%35 = call i64 @unzip(i8* %11, i8* %10)
%36 = icmp eq i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = call i64 @rm(i8* %10, i32 0)
br label %112
39: ; preds = %34
store i64 0, i64* %7
%40 = call i32 @strlen(i8* %10)
%41 = call i64 @sstrncat(i8* %9, i64* %7, i32 512, i8* %10, i32 %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %112
43: ; preds = %39
%44 = call i64 @sstrncat(i8* %9, i64* %7, i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %112
46: ; preds = %43
%47 = call i8* (...) @gethome()
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %112
52: ; preds = %46
store i64 0, i64* %7
%53 = call i32 @strlen(i8* %47)
%54 = call i64 @sstrncat(i8* %12, i64* %7, i32 512, i8* %47, i32 %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %112
56: ; preds = %52
%57 = call i64 @sstrncat(i8* %12, i64* %7, i32 512, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 7)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %112
59: ; preds = %56
%60 = call i64 @mkdir(i8* %12, i32 493)
%61 = icmp sgt i64 %60, 0
br i1 %61, label %62, label %70
62: ; preds = %59
%63 = load i64, i64* @errno
%64 = load i64, i64* @EEXIST
%65 = icmp eq i64 %63, %64
br i1 %65, label %70, label %66
66: ; preds = %62
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %12)
%69 = call i64 @rm(i8* %10, i32 0)
br label %112
70: ; preds = %62, %59
%71 = call i64 @sstrncat(i8* %12, i64* %7, i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %112
73: ; preds = %70
%74 = call i64 @sstrncat(i8* %12, i64* %7, i32 512, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 1)
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %112
76: ; preds = %73
%77 = call i64 @stat(i8* %12, %struct.stat* %2)
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %90
79: ; preds = %76
%80 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%81 = load i32, i32* %80
%82 = call i64 @S_ISDIR(i32 %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %90, label %84
84: ; preds = %79
%85 = call i64 @rm(i8* %12, i32 0)
%86 = icmp eq i64 %85, 0
br i1 %86, label %90, label %87
87: ; preds = %84
%88 = load i32, i32* @stderr
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %12)
br label %112
90: ; preds = %84, %79, %76
%91 = call i64 @rename(i8* %9, i8* %12)
%92 = icmp eq i64 %91, 0
br i1 %92, label %97, label %93
93: ; preds = %90
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i8* %9, i8* %12)
%96 = call i64 @rm(i8* %10, i32 0)
br label %112
97: ; preds = %90
%98 = call i64 @rm(i8* %10, i32 0)
%99 = icmp eq i64 %98, 0
br i1 %99, label %103, label %100
100: ; preds = %97
%101 = load i32, i32* @stderr
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %10)
br label %112
103: ; preds = %97
%104 = call i64 (...) @update_localdate()
%105 = icmp eq i64 %104, 0
br i1 %105, label %109, label %106
106: ; preds = %103
%107 = load i32, i32* @stderr
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0))
br label %112
109: ; preds = %103
%110 = load i32, i32* @stdout
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0))
br label %112
112: ; preds = %73, %70, %56, %52, %43, %39, %25, %22, %1, %109, %106, %100, %93, %87, %66, %49, %37, %31, %19
%113 = phi i32 [ 1, %19 ], [ 1, %31 ], [ 1, %37 ], [ 1, %49 ], [ 1, %66 ], [ 1, %87 ], [ 1, %93 ], [ 1, %100 ], [ 1, %106 ], [ 0, %109 ], [ 1, %1 ], [ 1, %22 ], [ 1, %25 ], [ 1, %39 ], [ 1, %43 ], [ 1, %52 ], [ 1, %56 ], [ 1, %70 ], [ 1, %73 ]
ret i32 %113
}