#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 */
char data_parity(short);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ printf(char *, char const *, short);
int /*<<< orphan*/ stderr;
short strtoul(char *, int /*<<< orphan*/ *, int);
char check_parity_and_print_voltage(char *data, const char *prefix) {
  char parity;
  short int val;
  parity = data[4] - '0';
  data[4] = '\0';
  val = strtoul(data, NULL, 16);
  if (parity != data_parity(val)) {
    fprintf(stderr, "%s: data parity error\n", prefix);
    return 0;
  }
  printf("\t%s voltage: %.2fV\n", prefix, val / 4095.0 * 6 * 2.485);
  return 1;
}


x86 assembly (clang, -O0):
<check_parity_and_print_voltage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%eax
sub    $0x30,%eax
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %ax,-0x1c(%rbp)
movsbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
movswl -0x1c(%rbp),%edi
call   1040 <data_parity@plt>
mov    %al,%cl
mov    -0x20(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
je     11be <check_parity_and_print_voltage+0x7e>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
movb   $0x0,-0x1(%rbp)
jmp    1205 <check_parity_and_print_voltage+0xc5>
mov    -0x18(%rbp),%rsi
movswl -0x1c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe2e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe2a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe26(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
lea    0xe36(%rip),%rdi
movswl %ax,%edx
call   1030 <printf@plt>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_parity_and_print_voltage>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x4(%rdi),%bl
add    $0xd0,%bl
movb   $0x0,0x4(%rdi)
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
movswl %ax,%ebp
mov    %ebp,%edi
call   1040 <data_parity@plt>
cmp    %al,%bl
jne    11a1 <check_parity_and_print_voltage+0x61>
cvtsi2sd %ebp,%xmm0
divsd  0xe89(%rip),%xmm0
mulsd  0xe89(%rip),%xmm0
mulsd  0xe89(%rip),%xmm0
cvttsd2si %xmm0,%eax
movswl %ax,%edx
lea    0xe9a(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    $0x1,%al
jmp    11bb <check_parity_and_print_voltage+0x7b>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"%s: data parity error\0A\00"
@.str.1 = [20 x i8] c"\09%s voltage: %.2fV\0A\00"
define signext i8 @check_parity_and_print_voltage(i8* %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i16
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = sub nsw i32 %11, 48
%13 = trunc i32 %12 to i8
store i8 %13, i8* %6
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 4
store i8 0, i8* %15
%16 = load i8*, i8** %4
%17 = call signext i16 @strtoul(i8* %16, i32* null, i32 16)
store i16 %17, i16* %7
%18 = load i8, i8* %6
%19 = sext i8 %18 to i32
%20 = load i16, i16* %7
%21 = call signext i8 @data_parity(i16 signext %20)
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %19, %22
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %5
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %26)
store i8 0, i8* %3
br label %38
28: ; preds = %2
%29 = load i8*, i8** %5
%30 = load i16, i16* %7
%31 = sext i16 %30 to i32
%32 = sitofp i32 %31 to double
%33 = fdiv double %32, 4.095000e+03
%34 = fmul double %33, 6.000000e+00
%35 = fmul double %34, 2.485000e+00
%36 = fptosi double %35 to i16
%37 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %29, i16 signext %36)
store i8 1, i8* %3
br label %38
38: ; preds = %28, %24
%39 = load i8, i8* %3
ret i8 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"%s: data parity error\0A\00"
@.str.1 = [20 x i8] c"\09%s voltage: %.2fV\0A\00"
define signext i8 @check_parity_and_print_voltage(i8* nocapture %0, i8* %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 4
%4 = load i8, i8* %3
%5 = add i8 %4, -48
store i8 0, i8* %3
%6 = tail call signext i16 @strtoul(i8* nocapture %0, i32* null, i32 16)
%7 = tail call signext i8 @data_parity(i16 signext %6)
%8 = icmp eq i8 %5, %7
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %19
12: ; preds = %2
%13 = sitofp i16 %6 to double
%14 = fdiv double %13, 4.095000e+03
%15 = fmul double %14, 6.000000e+00
%16 = fmul double %15, 2.485000e+00
%17 = fptosi double %16 to i16
%18 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %1, i16 signext %17)
br label %19
19: ; preds = %12, %9
%20 = phi i8 [ 0, %9 ], [ 1, %12 ]
ret i8 %20
}