#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*/ adc_set_chan(int /*<<< orphan*/);
int /*<<< orphan*/ gpio_a_analog(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read_bat(int);
int /*<<< orphan*/ relay_closed();
int /*<<< orphan*/ relay_open();
void measure_rint(void) {
  int v_open;
  int v_load;
  int dv;
  int rint;
  gpio_a_analog(0);
  adc_set_chan(0);
  relay_open();
  v_open = read_bat(20);
  printf("V open = %d\n", v_open);
  relay_closed();
  v_load = read_bat(20);
  printf("V loaded = %d\n", v_load);
  relay_open();
  dv = v_open - v_load;
  rint = dv * 5000 / v_load;
  printf("R int = %d (milliohms)\n", rint);
}


x86 assembly (clang, -O0):
<measure_rint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
call   1030 <gpio_a_analog@plt>
xor    %edi,%edi
call   1040 <adc_set_chan@plt>
mov    $0x0,%al
call   1070 <relay_open@plt>
mov    $0x14,%edi
call   1080 <read_bat@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe6c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <relay_closed@plt>
mov    $0x14,%edi
call   1080 <read_bat@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <relay_open@plt>
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
imul   $0x1388,-0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe38(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<measure_rint>:
push   %rbp
push   %rbx
push   %rax
xor    %edi,%edi
call   1030 <gpio_a_analog@plt>
xor    %edi,%edi
call   1040 <adc_set_chan@plt>
xor    %eax,%eax
call   1070 <relay_open@plt>
mov    $0x14,%edi
call   1080 <read_bat@plt>
mov    %eax,%ebx
lea    0xe75(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <relay_closed@plt>
mov    $0x14,%edi
call   1080 <read_bat@plt>
mov    %eax,%ebp
lea    0xe61(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <relay_open@plt>
sub    %ebp,%ebx
imul   $0x1388,%ebx,%eax
cltd
idiv   %ebp
lea    0xe50(%rip),%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"V open = %d\0A\00"
@.str.1 = [15 x i8] c"V loaded = %d\0A\00"
@.str.2 = [24 x i8] c"R int = %d (milliohms)\0A\00"
define void @measure_rint() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @gpio_a_analog(i32 0)
%6 = call i32 @adc_set_chan(i32 0)
%7 = call i32 (...) @relay_open()
%8 = call i32 @read_bat(i32 20)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 (...) @relay_closed()
%12 = call i32 @read_bat(i32 20)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 (...) @relay_open()
%16 = load i32, i32* %1
%17 = load i32, i32* %2
%18 = sub nsw i32 %16, %17
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = mul nsw i32 %19, 5000
%21 = load i32, i32* %2
%22 = sdiv i32 %20, %21
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %23)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"V open = %d\0A\00"
@.str.1 = [15 x i8] c"V loaded = %d\0A\00"
@.str.2 = [24 x i8] c"R int = %d (milliohms)\0A\00"
define void @measure_rint() {
%1 = tail call i32 @gpio_a_analog(i32 0)
%2 = tail call i32 @adc_set_chan(i32 0)
%3 = tail call i32 (...) @relay_open()
%4 = tail call i32 @read_bat(i32 20)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 (...) @relay_closed()
%7 = tail call i32 @read_bat(i32 20)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 (...) @relay_open()
%10 = sub nsw i32 %4, %7
%11 = mul nsw i32 %10, 5000
%12 = sdiv i32 %11, %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %12)
ret void
}