#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 */
scalar_t__ sstrncat(char *, size_t *, size_t, char const *, int);
int strlen(char const *);
int construct_url(char *buf, size_t buflen, char const *input,
                  char const *platform) {
  size_t len;
  len = 0;
  if (sstrncat(
          buf, &len, buflen,
          "https://raw.github.com/tldr-pages/tldr/master/pages",
          (sizeof("https://raw.github.com/tldr-pages/tldr/master/pages") - 1)))
    return 1;
  if (sstrncat(buf, &len, buflen, "/", 1))
    return 1;
  if (sstrncat(buf, &len, buflen, platform, strlen(platform)))
    return 1;
  if (sstrncat(buf, &len, buflen, "/", 1))
    return 1;
  if (sstrncat(buf, &len, buflen, input, strlen(input)))
    return 1;
  if (sstrncat(buf, &len, buflen, ".md", 3))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<construct_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rsi
lea    0xead(%rip),%rcx
mov    $0x33,%r8d
call   1040 <sstrncat@plt>
cmp    $0x0,%rax
je     1174 <construct_url+0x54>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <construct_url+0x195>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rsi
lea    0xead(%rip),%rcx
mov    $0x1,%r8d
call   1040 <sstrncat@plt>
cmp    $0x0,%rax
je     11a8 <construct_url+0x88>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <construct_url+0x195>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    %eax,%r8d
lea    -0x30(%rbp),%rsi
call   1040 <sstrncat@plt>
cmp    $0x0,%rax
je     11f7 <construct_url+0xd7>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <construct_url+0x195>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rsi
lea    0xe2a(%rip),%rcx
mov    $0x1,%r8d
call   1040 <sstrncat@plt>
cmp    $0x0,%rax
je     122b <construct_url+0x10b>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <construct_url+0x195>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    %eax,%r8d
lea    -0x30(%rbp),%rsi
call   1040 <sstrncat@plt>
cmp    $0x0,%rax
je     127a <construct_url+0x15a>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <construct_url+0x195>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rsi
lea    0xda9(%rip),%rcx
mov    $0x3,%r8d
call   1040 <sstrncat@plt>
cmp    $0x0,%rax
je     12ae <construct_url+0x18e>
movl   $0x1,-0x4(%rbp)
jmp    12b5 <construct_url+0x195>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<construct_url>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0xeb8(%rip),%rcx
lea    0x8(%rsp),%rsi
mov    %r14,%rdx
mov    $0x33,%r8d
call   1040 <sstrncat@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1227 <construct_url+0x107>
lea    0xec4(%rip),%rcx
lea    0x8(%rsp),%rsi
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x1,%r8d
call   1040 <sstrncat@plt>
test   %rax,%rax
jne    1227 <construct_url+0x107>
mov    %r12,%rdi
call   1030 <strlen@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %eax,%r8d
call   1040 <sstrncat@plt>
test   %rax,%rax
jne    1227 <construct_url+0x107>
lea    0xe76(%rip),%rcx
lea    0x8(%rsp),%rsi
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x1,%r8d
call   1040 <sstrncat@plt>
test   %rax,%rax
jne    1227 <construct_url+0x107>
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %eax,%r8d
call   1040 <sstrncat@plt>
test   %rax,%rax
jne    1227 <construct_url+0x107>
lea    0xe2e(%rip),%rcx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x3,%r8d
call   1040 <sstrncat@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"https://raw.github.com/tldr-pages/tldr/master/pages\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [4 x i8] c".md\00"
define i32 @construct_url(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i64 0, i64* %10
%11 = load i8*, i8** %6
%12 = load i64, i64* %7
%13 = call i64 @sstrncat(i8* %11, i64* %10, i64 %12, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 51)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 1, i32* %5
br label %53
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = load i64, i64* %7
%19 = call i64 @sstrncat(i8* %17, i64* %10, i64 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 1, i32* %5
br label %53
22: ; preds = %16
%23 = load i8*, i8** %6
%24 = load i64, i64* %7
%25 = load i8*, i8** %9
%26 = load i8*, i8** %9
%27 = call i32 @strlen(i8* %26)
%28 = call i64 @sstrncat(i8* %23, i64* %10, i64 %24, i8* %25, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %22
store i32 1, i32* %5
br label %53
31: ; preds = %22
%32 = load i8*, i8** %6
%33 = load i64, i64* %7
%34 = call i64 @sstrncat(i8* %32, i64* %10, i64 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 1, i32* %5
br label %53
37: ; preds = %31
%38 = load i8*, i8** %6
%39 = load i64, i64* %7
%40 = load i8*, i8** %8
%41 = load i8*, i8** %8
%42 = call i32 @strlen(i8* %41)
%43 = call i64 @sstrncat(i8* %38, i64* %10, i64 %39, i8* %40, i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %37
store i32 1, i32* %5
br label %53
46: ; preds = %37
%47 = load i8*, i8** %6
%48 = load i64, i64* %7
%49 = call i64 @sstrncat(i8* %47, i64* %10, i64 %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %46
store i32 1, i32* %5
br label %53
52: ; preds = %46
store i32 0, i32* %5
br label %53
53: ; preds = %52, %51, %45, %36, %30, %21, %15
%54 = load i32, i32* %5
ret i32 %54
}

LLVM IR (-O2):
@.str = [52 x i8] c"https://raw.github.com/tldr-pages/tldr/master/pages\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [4 x i8] c".md\00"
define i32 @construct_url(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%7 = call i64 @sstrncat(i8* %0, i64* %5, i64 %1, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 51)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %4
%10 = call i64 @sstrncat(i8* %0, i64* %5, i64 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = call i32 @strlen(i8* %3)
%14 = call i64 @sstrncat(i8* %0, i64* %5, i64 %1, i8* %3, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = call i64 @sstrncat(i8* %0, i64* %5, i64 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = call i32 @strlen(i8* %2)
%21 = call i64 @sstrncat(i8* %0, i64* %5, i64 %1, i8* %2, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = call i64 @sstrncat(i8* %0, i64* %5, i64 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%25 = icmp ne i64 %24, 0
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %23, %19, %16, %12, %9, %4
%28 = phi i32 [ 1, %4 ], [ 1, %9 ], [ 1, %12 ], [ 1, %16 ], [ 1, %19 ], [ %26, %23 ]
ret i32 %28
}