#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 */
char *malloc(int);
char *bar_str(char percent) {
  char *result = malloc(20 + 1);
  if (result == NULL)
    return NULL;
  result[0] = '[';
  result[20 - 1] = ']';
  result[20] = '\0';
  double temp = (100.0 / (20 - 2));
  int i = 1;
  while ((temp <= percent) && (i < 20 - 1)) {
    result[i] = '#';
    i++;
    temp += (100.0 / (20 - 2));
  }
  while (i < 20 - 1) {
    result[i] = '-';
    i++;
  }
  return result;
}


x86 assembly (clang, -O0):
<bar_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    $0x15,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1144 <bar_str+0x34>
movq   $0x0,-0x8(%rbp)
jmp    1202 <bar_str+0xf2>
mov    -0x18(%rbp),%rax
movb   $0x5b,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x5d,0x13(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x14(%rax)
movsd  0xe9d(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm1
movsbl -0x9(%rbp),%eax
cvtsi2sd %eax,%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
mov    %al,-0x25(%rbp)
jb     1195 <bar_str+0x85>
cmpl   $0x13,-0x24(%rbp)
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11a5 <bar_str+0x95>
jmp    11d1 <bar_str+0xc1>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x23,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  0xe3e(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    116f <bar_str+0x5f>
jmp    11d6 <bar_str+0xc6>
cmpl   $0x13,-0x24(%rbp)
jge    11fa <bar_str+0xea>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d6 <bar_str+0xc6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bar_str>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x15,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ad <bar_str+0x8d>
movb   $0x5b,(%rbx)
movw   $0x5d,0x13(%rbx)
mov    $0x1,%eax
cmp    $0x6,%bpl
jl     1190 <bar_str+0x70>
movsbl %bpl,%eax
cvtsi2sd %eax,%xmm0
movsd  0xea5(%rip),%xmm1
mov    $0x1,%ecx
movapd %xmm1,%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x23,(%rbx,%rcx,1)
lea    0x1(%rcx),%rax
addsd  %xmm1,%xmm2
ucomisd %xmm2,%xmm0
jb     118b <bar_str+0x6b>
cmp    $0x12,%rcx
mov    %rax,%rcx
jb     1170 <bar_str+0x50>
cmp    $0x12,%eax
ja     11ad <bar_str+0x8d>
mov    %eax,%ecx
mov    %rbx,%rdi
add    %rcx,%rdi
mov    $0x12,%edx
sub    %eax,%edx
add    $0x1,%rdx
mov    $0x2d,%esi
call   1030 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @bar_str(i8 signext %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32
store i8 %0, i8* %3
%7 = call i8* @malloc(i32 21)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %51
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 91, i8* %13
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 19
store i8 93, i8* %15
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 20
store i8 0, i8* %17
store double 0x401638E38E38E38E, double* %5
store i32 1, i32* %6
br label %18
18: ; preds = %29, %11
%19 = load double, double* %5
%20 = load i8, i8* %3
%21 = sext i8 %20 to i32
%22 = sitofp i32 %21 to double
%23 = fcmp ole double %19, %22
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 19
br label %27
27: ; preds = %24, %18
%28 = phi i1 [ false, %18 ], [ %26, %24 ]
br i1 %28, label %29, label %38
29: ; preds = %27
%30 = load i8*, i8** %4
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 35, i8* %33
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
%36 = load double, double* %5
%37 = fadd double %36, 0x401638E38E38E38E
store double %37, double* %5
br label %18
38: ; preds = %27
br label %39
39: ; preds = %42, %38
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 19
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = load i8*, i8** %4
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 45, i8* %46
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %39
49: ; preds = %39
%50 = load i8*, i8** %4
store i8* %50, i8** %2
br label %51
51: ; preds = %49, %10
%52 = load i8*, i8** %2
ret i8* %52
}

LLVM IR (-O2):
define noalias i8* @bar_str(i8 signext %0) {
%2 = tail call dereferenceable_or_null(21) i8* @malloc(i32 21)
%3 = icmp eq i8* %2, null
br i1 %3, label %28, label %4
4: ; preds = %1
store i8 91, i8* %2
%5 = getelementptr inbounds i8, i8* %2, i64 19
store i8 93, i8* %5
%6 = getelementptr inbounds i8, i8* %2, i64 20
store i8 0, i8* %6
%7 = sitofp i8 %0 to double
%8 = icmp sgt i8 %0, 5
br i1 %8, label %19, label %12
9: ; preds = %19
%10 = trunc i64 %23 to i32
%11 = icmp ult i32 %10, 19
br i1 %11, label %12, label %28
12: ; preds = %4, %9
%13 = phi i32 [ %10, %9 ], [ 1, %4 ]
%14 = zext i32 %13 to i64
%15 = getelementptr i8, i8* %2, i64 %14
%16 = sub nuw nsw i32 18, %13
%17 = zext i32 %16 to i64
%18 = add nuw nsw i64 %17, 1
br label %28
19: ; preds = %4, %19
%20 = phi i64 [ %23, %19 ], [ 1, %4 ]
%21 = phi double [ %24, %19 ], [ 0x401638E38E38E38E, %4 ]
%22 = getelementptr inbounds i8, i8* %2, i64 %20
store i8 35, i8* %22
%23 = add nuw nsw i64 %20, 1
%24 = fadd double %21, 0x401638E38E38E38E
%25 = fcmp ole double %24, %7
%26 = icmp ult i64 %20, 18
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %19, label %9
28: ; preds = %12, %9, %1
ret i8* %2
}