#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, float);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
void om_text_print_bar(FILE *fp, int max, int tot, int this, int cols, char c1,
                       char c2) {
  int l;
  float p;
  char *bar;
  if (tot == 0)
    tot++;
  if (max == 0)
    max++;
  l = ((float)(cols * this)) / max;
  p = ((float)(100 * this)) / tot;
  bar = malloc(cols + 1);
  if (!bar)
    return;
  memset(bar, c2, cols + 1);
  memset(bar, c1, l);
  bar[cols] = '\0';
  fprintf(fp, "%s %02.1f%%", bar, p);
  free(bar);
}


x86 assembly (clang, -O0):
<om_text_print_bar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r9b,%al
mov    0x10(%rbp),%r9b
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %al,-0x19(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1176 <om_text_print_bar+0x36>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1189 <om_text_print_bar+0x49>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x14(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
imul   $0x64,-0x14(%rbp),%eax
cvtsi2ss %eax,%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x18(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d9 <om_text_print_bar+0x99>
jmp    122e <om_text_print_bar+0xee>
mov    -0x30(%rbp),%rdi
mov    0x10(%rbp),%al
mov    -0x18(%rbp),%edx
add    $0x1,%edx
movsbl %al,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x19(%rbp),%al
mov    -0x20(%rbp),%edx
movsbl %al,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
movss  -0x24(%rbp),%xmm0
lea    0xde0(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_text_print_bar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8d,%r15d
mov    %ecx,%ebp
mov    %edx,%r12d
mov    %esi,%r14d
mov    %rdi,0x10(%rsp)
mov    0x50(%rsp),%al
mov    %al,0x7(%rsp)
lea    0x1(%r15),%r13d
mov    %r13d,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1217 <om_text_print_bar+0xd7>
mov    %rax,%rbx
test   %r14d,%r14d
mov    $0x1,%eax
cmove  %eax,%r14d
test   %r12d,%r12d
cmove  %eax,%r12d
imul   $0x64,%ebp,%eax
cvtsi2ss %eax,%xmm3
cvtsi2ss %r12d,%xmm0
imul   %r15d,%ebp
cvtsi2ss %ebp,%xmm1
cvtsi2ss %r14d,%xmm2
divss  %xmm0,%xmm3
movss  %xmm3,0x8(%rsp)
divss  %xmm2,%xmm1
cvttss2si %xmm1,%ebp
movsbl 0x7(%rsp),%esi
mov    %rbx,%rdi
mov    %r13d,%edx
call   1040 <memset@plt>
movsbl 0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <memset@plt>
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
lea    0xe12(%rip),%rsi
mov    0x10(%rsp),%rdi
mov    %rbx,%rdx
movss  0x8(%rsp),%xmm0
call   1050 <fprintf@plt>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s %02.1f%%\00"
define void @om_text_print_bar(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8 signext %5, i8 signext %6) {
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
%14 = alloca i8
%15 = alloca i32
%16 = alloca float
%17 = alloca i8*
store i32* %0, i32** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8 %5, i8* %13
store i8 %6, i8* %14
%18 = load i32, i32* %10
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %7
%21 = load i32, i32* %10
%22 = add nsw i32 %21, 1
store i32 %22, i32* %10
br label %23
23: ; preds = %20, %7
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %12
%31 = load i32, i32* %11
%32 = mul nsw i32 %30, %31
%33 = sitofp i32 %32 to float
%34 = load i32, i32* %9
%35 = sitofp i32 %34 to float
%36 = fdiv float %33, %35
%37 = fptosi float %36 to i32
store i32 %37, i32* %15
%38 = load i32, i32* %11
%39 = mul nsw i32 100, %38
%40 = sitofp i32 %39 to float
%41 = load i32, i32* %10
%42 = sitofp i32 %41 to float
%43 = fdiv float %40, %42
store float %43, float* %16
%44 = load i32, i32* %12
%45 = add nsw i32 %44, 1
%46 = call i8* @malloc(i32 %45)
store i8* %46, i8** %17
%47 = load i8*, i8** %17
%48 = icmp ne i8* %47, null
br i1 %48, label %50, label %49
49: ; preds = %29
br label %70
50: ; preds = %29
%51 = load i8*, i8** %17
%52 = load i8, i8* %14
%53 = load i32, i32* %12
%54 = add nsw i32 %53, 1
%55 = call i32 @memset(i8* %51, i8 signext %52, i32 %54)
%56 = load i8*, i8** %17
%57 = load i8, i8* %13
%58 = load i32, i32* %15
%59 = call i32 @memset(i8* %56, i8 signext %57, i32 %58)
%60 = load i8*, i8** %17
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
store i8 0, i8* %63
%64 = load i32*, i32** %8
%65 = load i8*, i8** %17
%66 = load float, float* %16
%67 = call i32 @fprintf(i32* %64, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %65, float %66)
%68 = load i8*, i8** %17
%69 = call i32 @free(i8* %68)
br label %70
70: ; preds = %50, %49
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s %02.1f%%\00"
define void @om_text_print_bar(i32* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4, i8 signext %5, i8 signext %6) {
%8 = add nsw i32 %4, 1
%9 = tail call i8* @malloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %31, label %11
11: ; preds = %7
%12 = icmp eq i32 %1, 0
%13 = select i1 %12, i32 1, i32 %1
%14 = icmp eq i32 %2, 0
%15 = select i1 %14, i32 1, i32 %2
%16 = mul nsw i32 %3, 100
%17 = sitofp i32 %16 to float
%18 = sitofp i32 %15 to float
%19 = fdiv float %17, %18
%20 = mul nsw i32 %4, %3
%21 = sitofp i32 %20 to float
%22 = sitofp i32 %13 to float
%23 = fdiv float %21, %22
%24 = fptosi float %23 to i32
%25 = tail call i32 @memset(i8* %9, i8 signext %6, i32 %8)
%26 = tail call i32 @memset(i8* %9, i8 signext %5, i32 %24)
%27 = sext i32 %4 to i64
%28 = getelementptr inbounds i8, i8* %9, i64 %27
store i8 0, i8* %28
%29 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %9, float %19)
%30 = tail call i32 @free(i8* %9)
br label %31
31: ; preds = %7, %11
ret void
}