#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 EXIT_SUCCESS;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int counter(unsigned int element, unsigned int nElements) {
  unsigned int percentage;
  percentage = (element * 100) / nElements;
  fprintf(stderr, "\rprocessing line: %d (%3d%% completed)", element,
          percentage);
  fflush(NULL);
  if (percentage == 100) {
    fprintf(stderr, "\n");
    fflush(NULL);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<counter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
imul   $0x64,-0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0xc(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xeb0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
cmpl   $0x64,-0xc(%rbp)
jne    118a <counter+0x6a>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<counter>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ecx
imul   $0x64,%edi,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%ebx
mov    0x2eaa(%rip),%r14
mov    (%r14),%edi
lea    0xec0(%rip),%rsi
mov    %ecx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1040 <fflush@plt>
cmp    $0x64,%ebx
jne    116f <counter+0x4f>
mov    (%r14),%edi
lea    0xec6(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1040 <fflush@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"\0Dprocessing line: %d (%3d%% completed)\00"
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @counter(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = mul i32 %6, 100
%8 = load i32, i32* %4
%9 = udiv i32 %7, %8
store i32 %9, i32* %5
%10 = load i32, i32* @stderr
%11 = load i32, i32* %3
%12 = load i32, i32* %5
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = call i32 @fflush(i32* null)
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 100
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @fflush(i32* null)
br label %21
21: ; preds = %17, %2
%22 = load i32, i32* @EXIT_SUCCESS
ret i32 %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"\0Dprocessing line: %d (%3d%% completed)\00"
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @counter(i32 %0, i32 %1) {
%3 = mul i32 %0, 100
%4 = udiv i32 %3, %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %4)
%7 = tail call i32 @fflush(i32* null)
%8 = icmp eq i32 %4, 100
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @fflush(i32* null)
br label %13
13: ; preds = %9, %2
%14 = load i32, i32* @EXIT_SUCCESS
ret i32 %14
}