#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*/ _IOLBF;
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ avrdude_message(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void update_progress_tty(int percent, double etime, char *hdr) {
  static char hashes[51];
  static char *header;
  static int last = 0;
  int i;
  setvbuf(stderr, (char *)NULL, _IONBF, 0);
  hashes[50] = 0;
  memset(hashes, ' ', 50);
  for (i = 0; i < percent; i += 2) {
    hashes[i / 2] = '#';
  }
  if (hdr) {
    avrdude_message((0), "\n");
    last = 0;
    header = hdr;
  }
  if (last == 0) {
    avrdude_message((0), "\r%s | %s | %d%% %0.2fs", header, hashes, percent,
                    etime);
  }
  if (percent == 100) {
    if (!last)
      avrdude_message((0), "\n\n");
    last = 1;
  }
  setvbuf(stderr, (char *)NULL, _IOLBF, 0);
}


x86 assembly (clang, -O0):
<update_progress_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
movb   $0x0,0x2f1a(%rip)
lea    0x2ee1(%rip),%rdi
mov    $0x20,%esi
mov    $0x32,%edx
call   1030 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b8 <update_progress_tty+0x88>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %eax,%rcx
lea    0x2eaa(%rip),%rax
movb   $0x23,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1185 <update_progress_tty+0x55>
cmpq   $0x0,-0x18(%rbp)
je     11e8 <update_progress_tty+0xb8>
xor    %edi,%edi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1040 <avrdude_message@plt>
movl   $0x0,0x2eb3(%rip)
mov    -0x18(%rbp),%rax
mov    %rax,0x2ea0(%rip)
cmpl   $0x0,0x2ea1(%rip)
jne    121c <update_progress_tty+0xec>
mov    0x2e8c(%rip),%rdx
mov    -0x4(%rbp),%r8d
movsd  -0x10(%rbp),%xmm0
xor    %edi,%edi
lea    0xdf2(%rip),%rsi
lea    0x2e3b(%rip),%rcx
mov    $0x1,%al
call   1040 <avrdude_message@plt>
cmpl   $0x64,-0x4(%rbp)
jne    124d <update_progress_tty+0x11d>
cmpl   $0x0,0x2e63(%rip)
jne    1243 <update_progress_tty+0x113>
xor    %edi,%edi
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1040 <avrdude_message@plt>
movl   $0x1,0x2e43(%rip)
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_progress_tty>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
movsd  %xmm0,0x8(%rsp)
mov    %edi,%ebx
mov    0x2e8d(%rip),%r15
mov    (%r15),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1050 <setvbuf@plt>
movb   $0x0,0x2f1b(%rip)
lea    0x2ee2(%rip),%rdi
mov    $0x20,%esi
mov    $0x32,%edx
call   1030 <memset@plt>
test   %ebx,%ebx
jle    119a <update_progress_tty+0x6a>
lea    -0x1(%rbx),%edx
shr    %edx
add    $0x1,%edx
lea    0x2ec0(%rip),%rdi
mov    $0x23,%esi
call   1030 <memset@plt>
test   %r14,%r14
je     11bf <update_progress_tty+0x8f>
lea    0xe72(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1040 <avrdude_message@plt>
movb   $0x0,0x2eda(%rip)
mov    %r14,0x2ecb(%rip)
jmp    11cf <update_progress_tty+0x9f>
cmpb   $0x0,0x2eca(%rip)
jne    11f2 <update_progress_tty+0xc2>
mov    0x2eb9(%rip),%r14
lea    0xe2a(%rip),%rsi
lea    0x2e73(%rip),%rcx
xor    %edi,%edi
mov    %r14,%rdx
mov    %ebx,%r8d
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <avrdude_message@plt>
cmp    $0x64,%ebx
jne    1217 <update_progress_tty+0xe7>
cmpb   $0x0,0x2e92(%rip)
jne    1210 <update_progress_tty+0xe0>
lea    0xe10(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1040 <avrdude_message@plt>
movb   $0x1,0x2e79(%rip)
mov    (%r15),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <setvbuf@plt>

LLVM IR (-O0):
@update_progress_tty.hashes = internal global [51 x i8] zeroinitializer
@update_progress_tty.header = internal global i8* null
@update_progress_tty.last = internal global i32 0
@stderr = global i32 0
@_IONBF = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [23 x i8] c"\0D%s | %s | %d%% %0.2fs\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@_IOLBF = global i32 0
define void @update_progress_tty(i32 %0, double %1, i8* %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store double %1, double* %5
store i8* %2, i8** %6
%8 = load i32, i32* @stderr
%9 = load i32, i32* @_IONBF
%10 = call i32 @setvbuf(i32 %8, i8* null, i32 %9, i32 0)
store i8 0, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @update_progress_tty.hashes, i64 0, i64 50)
%11 = call i32 @memset(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @update_progress_tty.hashes, i64 0, i64 0), i8 signext 32, i32 50)
store i32 0, i32* %7
br label %12
12: ; preds = %21, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %7
%18 = sdiv i32 %17, 2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [51 x i8], [51 x i8]* @update_progress_tty.hashes, i64 0, i64 %19
store i8 35, i8* %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 2
store i32 %23, i32* %7
br label %12
24: ; preds = %12
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* @update_progress_tty.last
%29 = load i8*, i8** %6
store i8* %29, i8** @update_progress_tty.header
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* @update_progress_tty.last
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i8*, i8** @update_progress_tty.header
%35 = load i32, i32* %4
%36 = load double, double* %5
%37 = call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @update_progress_tty.hashes, i64 0, i64 0), i32 %35, double %36)
br label %38
38: ; preds = %33, %30
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 100
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i32, i32* @update_progress_tty.last
%43 = icmp ne i32 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
store i32 1, i32* @update_progress_tty.last
br label %47
47: ; preds = %46, %38
%48 = load i32, i32* @stderr
%49 = load i32, i32* @_IOLBF
%50 = call i32 @setvbuf(i32 %48, i8* null, i32 %49, i32 0)
ret void
}

LLVM IR (-O2):
@update_progress_tty.hashes = internal global [51 x i8] zeroinitializer
@update_progress_tty.header = internal unnamed_addr global i8* null
@update_progress_tty.last = internal unnamed_addr global i1 false
@stderr = global i32 0
@_IONBF = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [23 x i8] c"\0D%s | %s | %d%% %0.2fs\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@_IOLBF = global i32 0
define void @update_progress_tty(i32 %0, double %1, i8* %2) {
%4 = load i32, i32* @stderr
%5 = load i32, i32* @_IONBF
%6 = tail call i32 @setvbuf(i32 %4, i8* null, i32 %5, i32 0)
store i8 0, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @update_progress_tty.hashes, i64 0, i64 50)
%7 = tail call i32 @memset(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @update_progress_tty.hashes, i64 0, i64 0), i8 signext 32, i32 50)
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = add nsw i32 %0, -1
%11 = lshr i32 %10, 1
%12 = add nuw nsw i32 %11, 1
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %9, %3
%15 = icmp eq i8* %2, null
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i1 false, i1* @update_progress_tty.last
store i8* %2, i8** @update_progress_tty.header
br label %22
18: ; preds = %14
%19 = load i1, i1* @update_progress_tty.last
br i1 %19, label %25, label %20
20: ; preds = %18
%21 = load i8*, i8** @update_progress_tty.header
br label %22
22: ; preds = %20, %16
%23 = phi i8* [ %21, %20 ], [ %2, %16 ]
%24 = tail call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @update_progress_tty.hashes, i64 0, i64 0), i32 %0, double %1)
br label %25
25: ; preds = %22, %18
%26 = icmp eq i32 %0, 100
br i1 %26, label %27, label %32
27: ; preds = %25
%28 = load i1, i1* @update_progress_tty.last
br i1 %28, label %31, label %29
29: ; preds = %27
%30 = tail call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
store i1 true, i1* @update_progress_tty.last
br label %32
32: ; preds = %31, %25
%33 = load i32, i32* @stderr
%34 = load i32, i32* @_IOLBF
%35 = tail call i32 @setvbuf(i32 %33, i8* null, i32 %34, i32 0)
ret void
}