#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 */
typedef int uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
scalar_t__ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
main(int argc, char *argv[]) {
  uint32_t a107, rs107, power_lsb, current_lsb;
  uint8_t shunt_mv;
  uint16_t shunt_amps, ina226_cal;
  if (argc != 3) {
    printf("Usage: caldb amps mv\n");
    exit(1);
  }
  shunt_mv = (uint8_t)atoi(argv[2]);
  shunt_amps = (uint16_t)atoi(argv[1]);
  printf("shunt_mv   = 0x%02X\n", shunt_mv);
  printf("shunt_amps = 0x%04X\n", shunt_amps);
  a107 = 10000000 * shunt_amps;
  rs107 = (shunt_mv * (10000000 / 1000)) / shunt_amps;
  printf("a107   = %u\n", a107);
  printf("rs107 = %u\n", rs107);
  current_lsb = a107 >> 15;
  power_lsb = 25 * current_lsb;
  printf("power_lsb   = %u\n", power_lsb);
  printf("current_lsb = %u\n", current_lsb);
  ina226_cal = (uint16_t)((512000000) / ((current_lsb * rs107) / 1000));
  printf("Cal value: %X\n", ina226_cal);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1168 <main+0x38>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
imul   $0x989680,-0x28(%rbp),%eax
mov    %eax,-0x14(%rbp)
imul   $0x2710,-0x24(%rbp),%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
sar    $0xf,%eax
mov    %eax,-0x20(%rbp)
imul   $0x19,-0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    $0x1e848000,%eax
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    121c <main+0xdc>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1050 <atoi@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
call   1050 <atoi@plt>
mov    %rax,%rbp
lea    0xe91(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
imul   $0x989680,%ebp,%ebx
imul   $0x2710,%r14d,%eax
cltd
idiv   %ebp
mov    %eax,%ebp
lea    0xe88(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe85(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
sar    $0xf,%ebx
lea    (%rbx,%rbx,4),%eax
lea    (%rax,%rax,4),%esi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
imul   %ebp,%ebx
movslq %ebx,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x26,%rcx
add    %eax,%ecx
mov    $0x1e848000,%eax
xor    %edx,%edx
idiv   %ecx
lea    0xe5b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Usage: caldb amps mv\0A\00"
@.str.1 = [21 x i8] c"shunt_mv = 0x%02X\0A\00"
@.str.2 = [21 x i8] c"shunt_amps = 0x%04X\0A\00"
@.str.3 = [13 x i8] c"a107 = %u\0A\00"
@.str.4 = [12 x i8] c"rs107 = %u\0A\00"
@.str.5 = [18 x i8] c"power_lsb = %u\0A\00"
@.str.6 = [18 x i8] c"current_lsb = %u\0A\00"
@.str.7 = [15 x i8] c"Cal value: %X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i64 @atoi(i8* %21)
%23 = trunc i64 %22 to i32
store i32 %23, i32* %10
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @atoi(i8* %26)
%28 = trunc i64 %27 to i32
store i32 %28, i32* %11
%29 = load i32, i32* %10
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %11
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %11
%34 = mul nsw i32 10000000, %33
store i32 %34, i32* %6
%35 = load i32, i32* %10
%36 = mul nsw i32 %35, 10000
%37 = load i32, i32* %11
%38 = sdiv i32 %36, %37
store i32 %38, i32* %7
%39 = load i32, i32* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %7
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %6
%44 = ashr i32 %43, 15
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = mul nsw i32 25, %45
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %9
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %9
%52 = load i32, i32* %7
%53 = mul nsw i32 %51, %52
%54 = sdiv i32 %53, 1000
%55 = sdiv i32 512000000, %54
store i32 %55, i32* %12
%56 = load i32, i32* %12
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %56)
%58 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"shunt_mv = 0x%02X\0A\00"
@.str.2 = [21 x i8] c"shunt_amps = 0x%04X\0A\00"
@.str.3 = [13 x i8] c"a107 = %u\0A\00"
@.str.4 = [12 x i8] c"rs107 = %u\0A\00"
@.str.5 = [18 x i8] c"power_lsb = %u\0A\00"
@.str.6 = [18 x i8] c"current_lsb = %u\0A\00"
@.str.7 = [15 x i8] c"Cal value: %X\0A\00"
@str = [21 x i8] c"Usage: caldb amps mv\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i64 @atoi(i8* %9)
%11 = trunc i64 %10 to i32
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @atoi(i8* %13)
%15 = trunc i64 %14 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%18 = mul nsw i32 %15, 10000000
%19 = mul nsw i32 %11, 10000
%20 = sdiv i32 %19, %15
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%23 = ashr i32 %18, 15
%24 = mul nsw i32 %23, 25
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%27 = mul nsw i32 %23, %20
%28 = sdiv i32 %27, 1000
%29 = sdiv i32 512000000, %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i32 %29)
%31 = tail call i32 @exit(i32 0)
unreachable
}