#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 adc_read();
int /*<<< orphan*/ delay_ms(int);
int /*<<< orphan*/ printf(char *, int);
void show_battery(int count, int delay) {
  int i;
  int val;
  for (i = 0; i < count; i++) {
    val = (adc_read() * 1000) / 681;
    printf("Battery: %d\n", val);
    delay_ms(delay);
  }
}


x86 assembly (clang, -O0):
<show_battery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118e <show_battery+0x5e>
mov    $0x0,%al
call   1040 <adc_read@plt>
imul   $0x3e8,%eax,%eax
mov    $0x2a9,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <delay_ms@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1145 <show_battery+0x15>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_battery>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
jle    1187 <show_battery+0x57>
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xebd(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <adc_read@plt>
imul   $0x3e8,%eax,%eax
cltq
imul   $0xc0784b3,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x25,%rsi
add    %eax,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <delay_ms@plt>
add    $0xffffffff,%ebp
jne    1150 <show_battery+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Battery: %d\0A\00"
define void @show_battery(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %19, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %22
11: ; preds = %7
%12 = call i32 (...) @adc_read()
%13 = mul nsw i32 %12, 1000
%14 = sdiv i32 %13, 681
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %4
%18 = call i32 @delay_ms(i32 %17)
br label %19
19: ; preds = %11
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %7
22: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"Battery: %d\0A\00"
define void @show_battery(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %13
4: ; preds = %2, %4
%5 = phi i32 [ %11, %4 ], [ 0, %2 ]
%6 = tail call i32 (...) @adc_read()
%7 = mul nsw i32 %6, 1000
%8 = sdiv i32 %7, 681
%9 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @delay_ms(i32 %1)
%11 = add nuw nsw i32 %5, 1
%12 = icmp eq i32 %11, %0
br i1 %12, label %13, label %4
13: ; preds = %4, %2
ret void
}