#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ renderWindow(char *, char const *, int, int, int *, int *);
int /*<<< orphan*/ setColor(int);
int /*<<< orphan*/ setCursor(int, int);
int strlen(char const *);
int /*<<< orphan*/ write(int, char *, int);
void drawProgress(const char *caption, const char *label, int progress,
                  int max) {
  int startX, startY;
  renderWindow("", caption, 60, 5, &startX, &startY);
  setCursor((uint8_t)(startX + (60 - strlen(label)) / 2),
            (uint8_t)(startY + 1));
  setColor(0x70);
  printf("%s", label);
  char bar[50];
  memset(bar, ' ', 50);
  memset(bar, 219, progress * 50 / max);
  setCursor((uint8_t)(startX + 5), (uint8_t)(startY + 3));
  setColor(0x0A);
  write(1, bar, 50);
  setCursor(79, 24);
}


x86 assembly (clang, -O0):
<drawProgress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x3c,%edx
mov    $0x5,%ecx
lea    -0x1c(%rbp),%r8
lea    -0x20(%rbp),%r9
call   1080 <renderWindow@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    %eax,%ecx
mov    $0x3c,%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    %eax,%edi
mov    -0x20(%rbp),%esi
add    $0x1,%esi
call   1060 <setCursor@plt>
mov    $0x70,%edi
call   1090 <setColor@plt>
mov    -0x10(%rbp),%rsi
lea    0xe13(%rip),%rdi
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x20,%esi
mov    $0x32,%edx
call   1070 <memset@plt>
lea    -0x60(%rbp),%rdi
imul   $0x32,-0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%edx
mov    $0xdb,%esi
call   1070 <memset@plt>
mov    -0x1c(%rbp),%edi
add    $0x5,%edi
mov    -0x20(%rbp),%esi
add    $0x3,%esi
call   1060 <setCursor@plt>
mov    $0xa,%edi
call   1090 <setColor@plt>
lea    -0x60(%rbp),%rsi
mov    $0x1,%edi
mov    $0x32,%edx
call   1030 <write@plt>
mov    $0x4f,%edi
mov    $0x18,%esi
call   1060 <setCursor@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drawProgress>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rsi
lea    0xe73(%rip),%rdi
mov    $0x3c,%ebp
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
mov    $0x3c,%edx
mov    $0x5,%ecx
call   1080 <renderWindow@plt>
mov    0xc(%rsp),%ebx
mov    %r12,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%edi
shr    $0x1f,%edi
add    %ebp,%edi
sar    %edi
add    %ebx,%edi
mov    0x8(%rsp),%esi
add    $0x1,%esi
call   1060 <setCursor@plt>
mov    $0x70,%edi
call   1090 <setColor@plt>
lea    0xe1d(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    $0x32,%edx
call   1070 <memset@plt>
imul   $0x32,%r15d,%eax
cltd
idiv   %r14d
mov    %rbx,%rdi
mov    $0xdb,%esi
mov    %eax,%edx
call   1070 <memset@plt>
mov    0xc(%rsp),%edi
add    $0x5,%edi
mov    0x8(%rsp),%esi
add    $0x3,%esi
call   1060 <setCursor@plt>
mov    $0xa,%edi
call   1090 <setColor@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x32,%edx
call   1030 <write@plt>
mov    $0x4f,%edi
mov    $0x18,%esi
call   1060 <setCursor@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
define void @drawProgress(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [50 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8*, i8** %5
%13 = call i32 @renderWindow(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %12, i32 60, i32 5, i32* %9, i32* %10)
%14 = load i32, i32* %9
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
%17 = sub nsw i32 60, %16
%18 = sdiv i32 %17, 2
%19 = add nsw i32 %14, %18
%20 = load i32, i32* %10
%21 = add nsw i32 %20, 1
%22 = call i32 @setCursor(i32 %19, i32 %21)
%23 = call i32 @setColor(i32 112)
%24 = load i8*, i8** %6
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 32, i32 50)
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%29 = load i32, i32* %7
%30 = mul nsw i32 %29, 50
%31 = load i32, i32* %8
%32 = sdiv i32 %30, %31
%33 = call i32 @memset(i8* %28, i32 219, i32 %32)
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 5
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 3
%38 = call i32 @setCursor(i32 %35, i32 %37)
%39 = call i32 @setColor(i32 10)
%40 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%41 = call i32 @write(i32 1, i8* %40, i32 50)
%42 = call i32 @setCursor(i32 79, i32 24)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
define void @drawProgress(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca [50 x i8]
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = call i32 @renderWindow(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0, i32 60, i32 5, i32* %5, i32* %6)
%11 = load i32, i32* %5
%12 = call i32 @strlen(i8* %1)
%13 = sub nsw i32 60, %12
%14 = sdiv i32 %13, 2
%15 = add nsw i32 %14, %11
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
%18 = call i32 @setCursor(i32 %15, i32 %17)
%19 = call i32 @setColor(i32 112)
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 32, i32 50)
%23 = mul nsw i32 %2, 50
%24 = sdiv i32 %23, %3
%25 = call i32 @memset(i8* %21, i32 219, i32 %24)
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 5
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 3
%30 = call i32 @setCursor(i32 %27, i32 %29)
%31 = call i32 @setColor(i32 10)
%32 = call i32 @write(i32 1, i8* %21, i32 50)
%33 = call i32 @setCursor(i32 79, i32 24)
ret void
}