#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*/ assert(char *);
int /*<<< orphan*/ base32_encode(char *, size_t *, char *, int);
int ceil(double);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int strlen(char *);
void build_base32_hostname(char *buf, size_t buf_size, char *file_name) {
  unsigned int plain_size, label_count;
  char *local_buf = malloc(buf_size);
  char *tmp = local_buf;
  assert(local_buf);
  {};
  plain_size = ceil(((double)buf_size - 1) / 8) * 5;
  {};
  plain_size -= plain_size / 62;
  {};
  while (strlen(file_name) > plain_size)
    file_name++;
  base32_encode(local_buf, &buf_size, file_name, strlen(file_name));
  {};
  label_count = 0;
  while (tmp < local_buf + strlen(local_buf) && buf < buf + buf_size) {
    *buf = *tmp;
    if (++label_count > 62) {
      buf++;
      *buf = '.';
      label_count = 0;
    }
    buf++;
    tmp++;
  }
  free(local_buf);
}


x86 assembly (clang, -O0):
<build_base32_hostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <assert@plt>
movaps 0xe77(%rip),%xmm1
movq   -0x10(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe76(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe47(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe33(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <ceil@plt>
imul   $0x5,%eax,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3e,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    -0x1c(%rbp),%eax
jbe    1215 <build_base32_hostname+0xb5>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11f2 <build_base32_hostname+0x92>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    %eax,%ecx
lea    -0x10(%rbp),%rsi
call   1080 <base32_encode@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rcx
cltq
add    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x41(%rbp)
jae    1291 <build_base32_hostname+0x131>
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    -0x10(%rbp),%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    12a1 <build_base32_hostname+0x141>
jmp    12f6 <build_base32_hostname+0x196>
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmp    $0x3e,%eax
jbe    12d9 <build_base32_hostname+0x179>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x2e,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1248 <build_base32_hostname+0xe8>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_base32_hostname>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,0x8(%rsp)
mov    %rsi,%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <assert@plt>
movq   %r12,%xmm1
punpckldq 0xe66(%rip),%xmm1
subpd  0xe6e(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
addsd  0xe6a(%rip),%xmm0
mulsd  0xe6a(%rip),%xmm0
call   1040 <ceil@plt>
lea    (%rax,%rax,4),%ebp
mov    %ebp,%eax
shr    %eax
mov    $0x84210843,%ecx
imul   %rax,%rcx
shr    $0x24,%rcx
sub    %ecx,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0x1,%rbx
cmp    %ebp,%eax
ja     11e0 <build_base32_hostname+0x80>
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1080 <base32_encode@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    126c <build_base32_hostname+0x10c>
cmpq   $0x0,0x8(%rsp)
jle    126c <build_base32_hostname+0x10c>
lea    0x1(%r14),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rbx),%eax
mov    %al,(%r15)
add    $0x1,%ebp
cmp    $0x3f,%ebp
jb     124a <build_base32_hostname+0xea>
movb   $0x2e,0x1(%r15)
add    $0x1,%r15
xor    %ebp,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
add    %r14,%rax
cmp    %rax,%rbx
jae    126c <build_base32_hostname+0x10c>
add    $0x1,%r15
add    $0x1,%rbx
cmpq   $0x0,0x8(%rsp)
jg     1230 <build_base32_hostname+0xd0>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @build_base32_hostname(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%11 = load i64, i64* %5
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
store i8* %13, i8** %10
%14 = load i8*, i8** %9
%15 = call i32 @assert(i8* %14)
%16 = load i64, i64* %5
%17 = uitofp i64 %16 to double
%18 = fsub double %17, 1.000000e+00
%19 = fdiv double %18, 8.000000e+00
%20 = call i32 @ceil(double %19)
%21 = mul nsw i32 %20, 5
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = udiv i32 %22, 62
%24 = load i32, i32* %7
%25 = sub i32 %24, %23
store i32 %25, i32* %7
br label %26
26: ; preds = %31, %3
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
%29 = load i32, i32* %7
%30 = icmp ugt i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %6
br label %26
34: ; preds = %26
%35 = load i8*, i8** %9
%36 = load i8*, i8** %6
%37 = load i8*, i8** %6
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @base32_encode(i8* %35, i64* %5, i8* %36, i32 %38)
store i32 0, i32* %8
br label %40
40: ; preds = %67, %34
%41 = load i8*, i8** %10
%42 = load i8*, i8** %9
%43 = load i8*, i8** %9
%44 = call i32 @strlen(i8* %43)
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = icmp ult i8* %41, %46
br i1 %47, label %48, label %54
48: ; preds = %40
%49 = load i8*, i8** %4
%50 = load i8*, i8** %4
%51 = load i64, i64* %5
%52 = getelementptr inbounds i8, i8* %50, i64 %51
%53 = icmp ult i8* %49, %52
br label %54
54: ; preds = %48, %40
%55 = phi i1 [ false, %40 ], [ %53, %48 ]
br i1 %55, label %56, label %72
56: ; preds = %54
%57 = load i8*, i8** %10
%58 = load i8, i8* %57
%59 = load i8*, i8** %4
store i8 %58, i8* %59
%60 = load i32, i32* %8
%61 = add i32 %60, 1
store i32 %61, i32* %8
%62 = icmp ugt i32 %61, 62
br i1 %62, label %63, label %67
63: ; preds = %56
%64 = load i8*, i8** %4
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %4
%66 = load i8*, i8** %4
store i8 46, i8* %66
store i32 0, i32* %8
br label %67
67: ; preds = %63, %56
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %4
%70 = load i8*, i8** %10
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %10
br label %40
72: ; preds = %54
%73 = load i8*, i8** %9
%74 = call i32 @free(i8* %73)
ret void
}

LLVM IR (-O2):
define void @build_base32_hostname(i8* nocapture writeonly %0, i64 %1, i8* %2) {
%4 = alloca i64
store i64 %1, i64* %4
%5 = tail call i8* @malloc(i64 %1)
%6 = tail call i32 @assert(i8* %5)
%7 = uitofp i64 %1 to double
%8 = fadd double %7, -1.000000e+00
%9 = fmul double %8, 1.250000e-01
%10 = tail call i32 @ceil(double %9)
%11 = mul nsw i32 %10, 5
%12 = udiv i32 %11, 62
%13 = sub i32 %11, %12
br label %14
14: ; preds = %14, %3
%15 = phi i8* [ %2, %3 ], [ %18, %14 ]
%16 = tail call i32 @strlen(i8* %15)
%17 = icmp ugt i32 %16, %13
%18 = getelementptr inbounds i8, i8* %15, i64 1
br i1 %17, label %14, label %19
19: ; preds = %14
%20 = tail call i32 @strlen(i8* %15)
%21 = call i32 @base32_encode(i8* %5, i64* %4, i8* %15, i32 %20)
%22 = call i32 @strlen(i8* %5)
%23 = icmp sgt i32 %22, 0
%24 = load i64, i64* %4
%25 = icmp sgt i64 %24, 0
%26 = select i1 %23, i1 %25, i1 false
br i1 %26, label %27, label %48
27: ; preds = %19, %36
%28 = phi i8* [ %40, %36 ], [ %5, %19 ]
%29 = phi i8* [ %39, %36 ], [ %0, %19 ]
%30 = phi i32 [ %37, %36 ], [ 0, %19 ]
%31 = load i8, i8* %28
store i8 %31, i8* %29
%32 = add i32 %30, 1
%33 = icmp ugt i32 %32, 62
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = getelementptr inbounds i8, i8* %29, i64 1
store i8 46, i8* %35
br label %36
36: ; preds = %34, %27
%37 = phi i32 [ 0, %34 ], [ %32, %27 ]
%38 = phi i8* [ %35, %34 ], [ %29, %27 ]
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = getelementptr inbounds i8, i8* %28, i64 1
%41 = call i32 @strlen(i8* %5)
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %5, i64 %42
%44 = icmp ult i8* %40, %43
%45 = load i64, i64* %4
%46 = icmp sgt i64 %45, 0
%47 = select i1 %44, i1 %46, i1 false
br i1 %47, label %27, label %48
48: ; preds = %36, %19
%49 = call i32 @free(i8* %5)
ret void
}