#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*/ setvbuf(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void update_progress_no_tty(int percent, double etime, char *hdr) {
  static int done = 0;
  static int last = 0;
  int cnt = (percent >> 1) * 2;
  setvbuf(stderr, (char *)NULL, _IONBF, 0);
  if (hdr) {
    avrdude_message((0), "\n%s | ", hdr);
    last = 0;
    done = 0;
  } else {
    while ((cnt > last) && (done == 0)) {
      avrdude_message((0), "#");
      cnt -= 2;
    }
  }
  if ((percent == 100) && (done == 0)) {
    avrdude_message((0), " | 100%% %0.2fs\n\n", etime);
    last = 0;
    done = 1;
  } else
    last = (percent >> 1) * 2;
  setvbuf(stderr, (char *)NULL, _IOLBF, 0);
}


x86 assembly (clang, -O0):
<update_progress_no_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1040 <setvbuf@plt>
cmpq   $0x0,-0x18(%rbp)
je     1195 <update_progress_no_tty+0x75>
mov    -0x18(%rbp),%rdx
xor    %edi,%edi
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1030 <avrdude_message@plt>
movl   $0x0,0x2eb2(%rip)
movl   $0x0,0x2ea4(%rip)
jmp    11ee <update_progress_no_tty+0xce>
jmp    119a <update_progress_no_tty+0x7a>
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    0x2e93(%rip),%ecx
mov    %al,-0x1d(%rbp)
jle    11bb <update_progress_no_tty+0x9b>
cmpl   $0x0,0x2e7f(%rip)
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11cb <update_progress_no_tty+0xab>
jmp    11e9 <update_progress_no_tty+0xc9>
xor    %edi,%edi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1030 <avrdude_message@plt>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    119a <update_progress_no_tty+0x7a>
jmp    11ee <update_progress_no_tty+0xce>
cmpl   $0x64,-0x4(%rbp)
jne    1233 <update_progress_no_tty+0x113>
cmpl   $0x0,0x2e35(%rip)
jne    1233 <update_progress_no_tty+0x113>
movsd  -0x10(%rbp),%xmm0
xor    %edi,%edi
lea    0xdf6(%rip),%rsi
mov    $0x1,%al
call   1030 <avrdude_message@plt>
movl   $0x0,0x2e14(%rip)
movl   $0x1,0x2e06(%rip)
jmp    1242 <update_progress_no_tty+0x122>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
shl    $0x1,%eax
mov    %eax,0x2df6(%rip)
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1040 <setvbuf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_progress_no_tty>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
movsd  %xmm0,(%rsp)
mov    %edi,%r15d
mov    %edi,%r12d
and    $0xfffffffe,%r12d
mov    0x2e94(%rip),%r14
mov    (%r14),%edi
mov    0x2e9a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1040 <setvbuf@plt>
test   %rbx,%rbx
je     11e6 <update_progress_no_tty+0xc6>
lea    0xe97(%rip),%rsi
xor    %ebp,%ebp
xor    %edi,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <avrdude_message@plt>
movl   $0x0,0x2eb7(%rip)
movb   $0x0,0x2eac(%rip)
cmp    $0x64,%r15d
jne    11bc <update_progress_no_tty+0x9c>
test   $0x1,%bpl
jne    11bc <update_progress_no_tty+0x9c>
lea    0xe6e(%rip),%rsi
xor    %edi,%edi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1030 <avrdude_message@plt>
movl   $0x0,0x2e85(%rip)
movb   $0x1,0x2e7a(%rip)
jmp    11c3 <update_progress_no_tty+0xa3>
mov    %r12d,0x2e75(%rip)
mov    (%r14),%edi
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <setvbuf@plt>
mov    0x2e47(%rip),%bpl
cmp    0x2e44(%rip),%r12d
jle    1188 <update_progress_no_tty+0x68>
test   $0x1,%bpl
jne    1188 <update_progress_no_tty+0x68>
lea    -0x2(%r12),%ebx
lea    0xdff(%rip),%r13
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <avrdude_message@plt>
movzbl 0x2e11(%rip),%ebp
cmp    0x2e0f(%rip),%ebx
jle    1188 <update_progress_no_tty+0x68>
add    $0xfffffffe,%ebx
test   $0x1,%bpl
je     1210 <update_progress_no_tty+0xf0>
jmp    1188 <update_progress_no_tty+0x68>

LLVM IR (-O0):
@update_progress_no_tty.done = internal global i32 0
@update_progress_no_tty.last = internal global i32 0
@stderr = global i32 0
@_IONBF = global i32 0
@.str = [7 x i8] c"\0A%s | \00"
@.str.1 = [2 x i8] c"#\00"
@.str.2 = [18 x i8] c" | 100%% %0.2fs\0A\0A\00"
@_IOLBF = global i32 0
define void @update_progress_no_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* %4
%9 = ashr i32 %8, 1
%10 = mul nsw i32 %9, 2
store i32 %10, i32* %7
%11 = load i32, i32* @stderr
%12 = load i32, i32* @_IONBF
%13 = call i32 @setvbuf(i32 %11, i8* null, i32 %12, i32 0)
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 0, i32* @update_progress_no_tty.last
store i32 0, i32* @update_progress_no_tty.done
br label %34
19: ; preds = %3
br label %20
20: ; preds = %29, %19
%21 = load i32, i32* %7
%22 = load i32, i32* @update_progress_no_tty.last
%23 = icmp sgt i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @update_progress_no_tty.done
%26 = icmp eq i32 %25, 0
br label %27
27: ; preds = %24, %20
%28 = phi i1 [ false, %20 ], [ %26, %24 ]
br i1 %28, label %29, label %33
29: ; preds = %27
%30 = call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* %7
%32 = sub nsw i32 %31, 2
store i32 %32, i32* %7
br label %20
33: ; preds = %27
br label %34
34: ; preds = %33, %16
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 100
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i32, i32* @update_progress_no_tty.done
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load double, double* %5
%42 = call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %41)
store i32 0, i32* @update_progress_no_tty.last
store i32 1, i32* @update_progress_no_tty.done
br label %47
43: ; preds = %37, %34
%44 = load i32, i32* %4
%45 = ashr i32 %44, 1
%46 = mul nsw i32 %45, 2
store i32 %46, i32* @update_progress_no_tty.last
br label %47
47: ; preds = %43, %40
%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_no_tty.done = internal unnamed_addr global i1 false
@update_progress_no_tty.last = internal unnamed_addr global i32 0
@stderr = global i32 0
@_IONBF = global i32 0
@.str = [7 x i8] c"\0A%s | \00"
@.str.1 = [2 x i8] c"#\00"
@.str.2 = [18 x i8] c" | 100%% %0.2fs\0A\0A\00"
@_IOLBF = global i32 0
define void @update_progress_no_tty(i32 %0, double %1, i8* %2) {
%4 = and i32 %0, -2
%5 = load i32, i32* @stderr
%6 = load i32, i32* @_IONBF
%7 = tail call i32 @setvbuf(i32 %5, i8* null, i32 %6, i32 0)
%8 = icmp eq i8* %2, null
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = load i32, i32* @update_progress_no_tty.last
%11 = icmp sgt i32 %4, %10
%12 = load i1, i1* @update_progress_no_tty.done
%13 = xor i1 %12, true
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %17, label %26
15: ; preds = %3
%16 = tail call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %2)
store i32 0, i32* @update_progress_no_tty.last
store i1 false, i1* @update_progress_no_tty.done
br label %26
17: ; preds = %9, %17
%18 = phi i32 [ %20, %17 ], [ %4, %9 ]
%19 = tail call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = add nsw i32 %18, -2
%21 = load i32, i32* @update_progress_no_tty.last
%22 = icmp sgt i32 %20, %21
%23 = load i1, i1* @update_progress_no_tty.done
%24 = xor i1 %23, true
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %17, label %26
26: ; preds = %17, %9, %15
%27 = phi i1 [ %12, %9 ], [ false, %15 ], [ %23, %17 ]
%28 = icmp eq i32 %0, 100
%29 = xor i1 %27, true
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = tail call i32 (i32, i8*, ...) @avrdude_message(i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), double %1)
store i32 0, i32* @update_progress_no_tty.last
store i1 true, i1* @update_progress_no_tty.done
br label %34
33: ; preds = %26
store i32 %4, i32* @update_progress_no_tty.last
br label %34
34: ; preds = %33, %31
%35 = load i32, i32* @stderr
%36 = load i32, i32* @_IOLBF
%37 = tail call i32 @setvbuf(i32 %35, i8* null, i32 %36, i32 0)
ret void
}