#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *gethome();
char *getplatform();
int /*<<< orphan*/ parse_tldrlist(char *, char const *);
scalar_t__ sstrncat(char *, size_t *, int, char const *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char const *, char *);
int strlen(char const *);
int print_tldrlist(char const *poverride) {
  char const *platform;
  char const *homedir;
  size_t len;
  char directory[512];
  if (poverride == NULL) {
    platform = getplatform();
  } else {
    platform = poverride;
    if (strcmp(platform, "linux") != 0 && strcmp(platform, "osx") != 0 &&
        strcmp(platform, "common") != 0 && strcmp(platform, "sunos") != 0 &&
        strcmp(platform, "windows") != 0) {
      fprintf(stderr, "Error: platform %s is unsupported\n", platform);
      fprintf(stderr,
              "Supported platforms: linux / osx / sunos / windows / common\n");
      exit(EXIT_FAILURE);
    }
  }
  homedir = gethome();
  if (homedir == NULL)
    return 1;
  len = 0;
  if (sstrncat(directory, &len, 512, homedir, strlen(homedir)))
    return 1;
  if (sstrncat(directory, &len, 512, "/.tldrc/tldr-master/pages/",
               (sizeof("/.tldrc/tldr-master/pages/") - 1)))
    return 1;
  if (strcmp(platform, "common") != 0) {
    parse_tldrlist(directory, platform);
    fprintf(stdout, "\n");
  }
  parse_tldrlist(directory, "common");
  return 0;
}


x86 assembly (clang, -O0):
<print_tldrlist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11aa <print_tldrlist+0x2a>
mov    $0x0,%al
call   1080 <getplatform@plt>
mov    %rax,-0x18(%rbp)
jmp    1279 <print_tldrlist+0xf9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1274 <print_tldrlist+0xf4>
mov    -0x18(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1274 <print_tldrlist+0xf4>
mov    -0x18(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1274 <print_tldrlist+0xf4>
mov    -0x18(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1274 <print_tldrlist+0xf4>
mov    -0x18(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1274 <print_tldrlist+0xf4>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1279 <print_tldrlist+0xf9>
mov    $0x0,%al
call   10a0 <gethome@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    129b <print_tldrlist+0x11b>
movl   $0x1,-0x4(%rbp)
jmp    138d <print_tldrlist+0x20d>
movq   $0x0,-0x28(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x240(%rbp),%rdi
mov    -0x238(%rbp),%rcx
mov    %eax,%r8d
lea    -0x28(%rbp),%rsi
mov    $0x200,%edx
call   1050 <sstrncat@plt>
cmp    $0x0,%rax
je     12fa <print_tldrlist+0x17a>
movl   $0x1,-0x4(%rbp)
jmp    138d <print_tldrlist+0x20d>
lea    -0x230(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x200,%edx
lea    0xd6e(%rip),%rcx
mov    $0x1a,%r8d
call   1050 <sstrncat@plt>
cmp    $0x0,%rax
je     1332 <print_tldrlist+0x1b2>
movl   $0x1,-0x4(%rbp)
jmp    138d <print_tldrlist+0x20d>
mov    -0x18(%rbp),%rdi
lea    0xccd(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1373 <print_tldrlist+0x1f3>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <parse_tldrlist@plt>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
lea    0xcd4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    -0x230(%rbp),%rdi
lea    0xc89(%rip),%rsi
call   1030 <parse_tldrlist@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_tldrlist>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
test   %rdi,%rdi
je     1234 <print_tldrlist+0xb4>
mov    %rdi,%r14
lea    0xe62(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     123e <print_tldrlist+0xbe>
lea    0xe53(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     123e <print_tldrlist+0xbe>
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     123e <print_tldrlist+0xbe>
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     123e <print_tldrlist+0xbe>
lea    0xe28(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     123e <print_tldrlist+0xbe>
mov    0x2ddd(%rip),%rbx
mov    (%rbx),%edi
lea    0xe13(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   1080 <getplatform@plt>
mov    %rax,%r14
xor    %eax,%eax
call   10a0 <gethome@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     12f7 <print_tldrlist+0x177>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x200,%edx
mov    %rbx,%rcx
mov    %eax,%r8d
call   1050 <sstrncat@plt>
test   %rax,%rax
jne    12f7 <print_tldrlist+0x177>
lea    0xdf2(%rip),%rcx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x200,%edx
mov    $0x1a,%r8d
call   1050 <sstrncat@plt>
test   %rax,%rax
jne    12f7 <print_tldrlist+0x177>
lea    0xd57(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12e4 <print_tldrlist+0x164>
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1030 <parse_tldrlist@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    0xd63(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xd1f(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <parse_tldrlist@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"linux\00"
@.str.1 = [4 x i8] c"osx\00"
@.str.2 = [7 x i8] c"common\00"
@.str.3 = [6 x i8] c"sunos\00"
@.str.4 = [8 x i8] c"windows\00"
@stderr = global i32 0
@.str.5 = [35 x i8] c"Error: platform %s is unsupported\0A\00"
@.str.6 = [61 x i8] c"Supported platforms: linux / osx / sunos / windows / common\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [27 x i8] c"/.tldrc/tldr-master/pages/\00"
@stdout = global i32 0
@.str.8 = [2 x i8] c"\0A\00"
define i32 @print_tldrlist(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [512 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i8* (...) @getplatform()
store i8* %11, i8** %4
br label %42
12: ; preds = %1
%13 = load i8*, i8** %3
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %41
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %41
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %41
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %4
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.6, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %29, %25, %21, %17, %12
br label %42
42: ; preds = %41, %10
%43 = call i8* (...) @gethome()
store i8* %43, i8** %5
%44 = load i8*, i8** %5
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 1, i32* %2
br label %73
47: ; preds = %42
store i64 0, i64* %6
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%49 = load i8*, i8** %5
%50 = load i8*, i8** %5
%51 = call i32 @strlen(i8* %50)
%52 = call i64 @sstrncat(i8* %48, i64* %6, i32 512, i8* %49, i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %47
store i32 1, i32* %2
br label %73
55: ; preds = %47
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%57 = call i64 @sstrncat(i8* %56, i64* %6, i32 512, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 26)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 1, i32* %2
br label %73
60: ; preds = %55
%61 = load i8*, i8** %4
%62 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%66 = load i8*, i8** %4
%67 = call i32 @parse_tldrlist(i8* %65, i8* %66)
%68 = load i32, i32* @stdout
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %70
70: ; preds = %64, %60
%71 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%72 = call i32 @parse_tldrlist(i8* %71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %73
73: ; preds = %70, %59, %54, %46
%74 = load i32, i32* %2
ret i32 %74
}

LLVM IR (-O2):
@.str = [6 x i8] c"linux\00"
@.str.1 = [4 x i8] c"osx\00"
@.str.2 = [7 x i8] c"common\00"
@.str.3 = [6 x i8] c"sunos\00"
@.str.4 = [8 x i8] c"windows\00"
@stderr = global i32 0
@.str.5 = [35 x i8] c"Error: platform %s is unsupported\0A\00"
@.str.6 = [61 x i8] c"Supported platforms: linux / osx / sunos / windows / common\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [27 x i8] c"/.tldrc/tldr-master/pages/\00"
@stdout = global i32 0
@.str.8 = [2 x i8] c"\0A\00"
define i32 @print_tldrlist(i8* %0) {
%2 = alloca i64
%3 = alloca [512 x i8]
%4 = bitcast i64* %2 to i8*
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i8* (...) @getplatform()
br label %31
9: ; preds = %1
%10 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %31, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %31, label %15
15: ; preds = %12
%16 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %31, label %18
18: ; preds = %15
%19 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %31, label %21
21: ; preds = %18
%22 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.6, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %9, %12, %15, %18, %21, %7
%32 = phi i8* [ %8, %7 ], [ %0, %21 ], [ %0, %18 ], [ %0, %15 ], [ %0, %12 ], [ %0, %9 ]
%33 = tail call i8* (...) @gethome()
%34 = icmp eq i8* %33, null
br i1 %34, label %51, label %35
35: ; preds = %31
store i64 0, i64* %2
%36 = tail call i32 @strlen(i8* %33)
%37 = call i64 @sstrncat(i8* %5, i64* %2, i32 512, i8* %33, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %35
%40 = call i64 @sstrncat(i8* %5, i64* %2, i32 512, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 26)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %42
%46 = call i32 @parse_tldrlist(i8* %5, i8* %32)
%47 = load i32, i32* @stdout
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %49
49: ; preds = %45, %42
%50 = call i32 @parse_tldrlist(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %39, %35, %31, %49
%52 = phi i32 [ 0, %49 ], [ 1, %31 ], [ 1, %35 ], [ 1, %39 ]
ret i32 %52
}