#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*/ printf(char *, ...);
void progress_mode2_cb(const char *msg, int pos, int size) {
  static int old_count;
  if (pos != -1 && size != -1) {
    if (pos == 0) {
      old_count = 0;
      printf("%-15s: [", msg);
    } else if (pos <= size) {
      int i;
      int count = (pos * 50 / size);
      for (i = old_count; i < count; i++)
        printf("*");
      old_count = count;
      if (pos == size) {
        printf("] (%d)\n", pos);
      }
    }
  }
}


x86 assembly (clang, -O0):
<progress_mode2_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     11de <progress_mode2_cb+0xce>
cmpl   $0xffffffff,-0x10(%rbp)
je     11de <progress_mode2_cb+0xce>
cmpl   $0x0,-0xc(%rbp)
jne    1161 <progress_mode2_cb+0x51>
movl   $0x0,0x2ee2(%rip)
mov    -0x8(%rbp),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d9 <progress_mode2_cb+0xc9>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11d4 <progress_mode2_cb+0xc4>
imul   $0x32,-0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x18(%rbp)
mov    0x2eae(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a9 <progress_mode2_cb+0x99>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <progress_mode2_cb+0x71>
mov    -0x18(%rbp),%eax
mov    %eax,0x2e7a(%rip)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11cf <progress_mode2_cb+0xbf>
mov    -0xc(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d4 <progress_mode2_cb+0xc4>
jmp    11d9 <progress_mode2_cb+0xc9>
jmp    11de <progress_mode2_cb+0xce>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progress_mode2_cb>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
cmp    $0xffffffff,%esi
je     1195 <progress_mode2_cb+0x75>
mov    %edx,%r15d
cmp    $0xffffffff,%edx
je     1195 <progress_mode2_cb+0x75>
test   %ebx,%ebx
je     11a0 <progress_mode2_cb+0x80>
cmp    %r15d,%ebx
jg     1195 <progress_mode2_cb+0x75>
imul   $0x32,%ebx,%eax
cltd
idiv   %r15d
mov    %eax,%r14d
mov    0x2ee5(%rip),%eax
cmp    %r14d,%eax
jge    116f <progress_mode2_cb+0x4f>
mov    %r14d,%ebp
sub    %eax,%ebp
nopl   0x0(%rax)
mov    $0x2a,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1160 <progress_mode2_cb+0x40>
mov    %r14d,0x2ebe(%rip)
cmp    %r15d,%ebx
jne    1195 <progress_mode2_cb+0x75>
lea    0xe87(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rdi,%rsi
movl   $0x0,0x2e87(%rip)
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@progress_mode2_cb.old_count = internal global i32 0
@.str = [9 x i8] c"%-15s: [\00"
@.str.1 = [2 x i8] c"*\00"
@.str.2 = [8 x i8] c"] (%d)\0A\00"
define void @progress_mode2_cb(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %50
11: ; preds = %3
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %50
14: ; preds = %11
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
store i32 0, i32* @progress_mode2_cb.old_count
%18 = load i8*, i8** %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %49
20: ; preds = %14
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %48
24: ; preds = %20
%25 = load i32, i32* %5
%26 = mul nsw i32 %25, 50
%27 = load i32, i32* %6
%28 = sdiv i32 %26, %27
store i32 %28, i32* %8
%29 = load i32, i32* @progress_mode2_cb.old_count
store i32 %29, i32* %7
br label %30
30: ; preds = %36, %24
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %30
39: ; preds = %30
%40 = load i32, i32* %8
store i32 %40, i32* @progress_mode2_cb.old_count
%41 = load i32, i32* %5
%42 = load i32, i32* %6
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i32, i32* %5
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %39
br label %48
48: ; preds = %47, %20
br label %49
49: ; preds = %48, %17
br label %50
50: ; preds = %49, %11, %3
ret void
}

LLVM IR (-O2):
@progress_mode2_cb.old_count = internal unnamed_addr global i32 0
@.str = [9 x i8] c"%-15s: [\00"
@.str.2 = [8 x i8] c"] (%d)\0A\00"
define void @progress_mode2_cb(i8* %0, i32 %1, i32 %2) {
%4 = icmp ne i32 %1, -1
%5 = icmp ne i32 %2, -1
%6 = and i1 %4, %5
br i1 %6, label %7, label %27
7: ; preds = %3
%8 = icmp eq i32 %1, 0
br i1 %8, label %9, label %11
9: ; preds = %7
store i32 0, i32* @progress_mode2_cb.old_count
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %27
11: ; preds = %7
%12 = icmp sgt i32 %1, %2
br i1 %12, label %27, label %13
13: ; preds = %11
%14 = mul nsw i32 %1, 50
%15 = sdiv i32 %14, %2
%16 = load i32, i32* @progress_mode2_cb.old_count
%17 = icmp slt i32 %16, %15
br i1 %17, label %18, label %23
18: ; preds = %13, %18
%19 = phi i32 [ %21, %18 ], [ %16, %13 ]
%20 = tail call i32 @putchar(i32 42)
%21 = add i32 %19, 1
%22 = icmp eq i32 %21, %15
br i1 %22, label %23, label %18
23: ; preds = %18, %13
store i32 %15, i32* @progress_mode2_cb.old_count
%24 = icmp eq i32 %1, %2
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %27
27: ; preds = %23, %25, %9, %11, %3
ret void
}