#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 */
scalar_t__ acpi_get_property(char *, char *, char *);
int sscanf(char *, char *, unsigned int *);
double acpi_get_percent(char *battery_id) {
  char val_full[64], val_now[64];
  unsigned int full;
  unsigned int now;
  if (acpi_get_property(val_full, battery_id, "charge_full") &&
      sscanf(val_full, "%d", &full) == 1) {
    if (acpi_get_property(val_now, battery_id, "charge_now") &&
        sscanf(val_now, "%d", &now)) {
      return ((double)now / (double)full);
    }
  }
  if (acpi_get_property(val_full, battery_id, "energy_full") &&
      sscanf(val_full, "%d", &full) == 1) {
    if (acpi_get_property(val_now, battery_id, "energy_now") &&
        sscanf(val_now, "%d", &now)) {
      return ((double)now / (double)full);
    }
  }
  return 0.0;
}


x86 assembly (clang, -O0):
<acpi_get_percent>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xec2(%rip),%rdx
call   1030 <acpi_get_property@plt>
cmp    $0x0,%rax
je     11da <acpi_get_percent+0xba>
lea    -0x50(%rbp),%rdi
lea    0xeb4(%rip),%rsi
lea    -0x94(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11da <acpi_get_percent+0xba>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe90(%rip),%rdx
call   1030 <acpi_get_property@plt>
cmp    $0x0,%rax
je     11d5 <acpi_get_percent+0xb5>
lea    -0x90(%rbp),%rdi
lea    0xe70(%rip),%rsi
lea    -0x98(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x0,%eax
je     11d5 <acpi_get_percent+0xb5>
mov    -0x98(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x94(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128d <acpi_get_percent+0x16d>
jmp    11da <acpi_get_percent+0xba>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe31(%rip),%rdx
call   1030 <acpi_get_property@plt>
cmp    $0x0,%rax
je     1285 <acpi_get_percent+0x165>
lea    -0x50(%rbp),%rdi
lea    0xe09(%rip),%rsi
lea    -0x94(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1285 <acpi_get_percent+0x165>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xdfc(%rip),%rdx
call   1030 <acpi_get_property@plt>
cmp    $0x0,%rax
je     1280 <acpi_get_percent+0x160>
lea    -0x90(%rbp),%rdi
lea    0xdc5(%rip),%rsi
lea    -0x98(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x0,%eax
je     1280 <acpi_get_percent+0x160>
mov    -0x98(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    -0x94(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128d <acpi_get_percent+0x16d>
jmp    1285 <acpi_get_percent+0x165>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acpi_get_percent>:
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%rbx
lea    0xece(%rip),%rdx
lea    0x50(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <acpi_get_property@plt>
test   %rax,%rax
je     1192 <acpi_get_percent+0x72>
lea    0xec1(%rip),%rsi
lea    0x50(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <acpi_get_percent+0x72>
lea    0xea9(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <acpi_get_property@plt>
test   %rax,%rax
je     1192 <acpi_get_percent+0x72>
lea    0xe8d(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
call   1040 <sscanf@plt>
test   %eax,%eax
jne    1201 <acpi_get_percent+0xe1>
lea    0xe81(%rip),%rdx
lea    0x50(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <acpi_get_property@plt>
xorpd  %xmm0,%xmm0
test   %rax,%rax
je     1220 <acpi_get_percent+0x100>
lea    0xe56(%rip),%rsi
lea    0x50(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    121c <acpi_get_percent+0xfc>
lea    0xe55(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <acpi_get_property@plt>
test   %rax,%rax
je     121c <acpi_get_percent+0xfc>
lea    0xe22(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
call   1040 <sscanf@plt>
test   %eax,%eax
xorpd  %xmm0,%xmm0
je     1220 <acpi_get_percent+0x100>
mov    0x8(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0xc(%rsp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
jmp    1220 <acpi_get_percent+0x100>
xorpd  %xmm0,%xmm0
add    $0x90,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"charge_full\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"charge_now\00"
@.str.3 = [12 x i8] c"energy_full\00"
@.str.4 = [11 x i8] c"energy_now\00"
define double @acpi_get_percent(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca [64 x i8]
%5 = alloca [64 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i64 @acpi_get_property(i8* %8, i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %32
12: ; preds = %1
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%18 = load i8*, i8** %3
%19 = call i64 @acpi_get_property(i8* %17, i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %16
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i32, i32* %7
%27 = uitofp i32 %26 to double
%28 = load i32, i32* %6
%29 = uitofp i32 %28 to double
%30 = fdiv double %27, %29
store double %30, double* %2
br label %58
31: ; preds = %21, %16
br label %32
32: ; preds = %31, %12, %1
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%34 = load i8*, i8** %3
%35 = call i64 @acpi_get_property(i8* %33, i8* %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %57
37: ; preds = %32
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %57
41: ; preds = %37
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%43 = load i8*, i8** %3
%44 = call i64 @acpi_get_property(i8* %42, i8* %43, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %56
46: ; preds = %41
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%48 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %46
%51 = load i32, i32* %7
%52 = uitofp i32 %51 to double
%53 = load i32, i32* %6
%54 = uitofp i32 %53 to double
%55 = fdiv double %52, %54
store double %55, double* %2
br label %58
56: ; preds = %46, %41
br label %57
57: ; preds = %56, %37, %32
store double 0.000000e+00, double* %2
br label %58
58: ; preds = %57, %50, %25
%59 = load double, double* %2
ret double %59
}

LLVM IR (-O2):
@.str = [12 x i8] c"charge_full\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"charge_now\00"
@.str.3 = [12 x i8] c"energy_full\00"
@.str.4 = [11 x i8] c"energy_now\00"
define double @acpi_get_percent(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [64 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i64 @acpi_get_property(i8* %6, i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %27, label %12
12: ; preds = %1
%13 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = call i64 @acpi_get_property(i8* %7, i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %15
%19 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%20 = icmp eq i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = load i32, i32* %5
%23 = uitofp i32 %22 to double
%24 = load i32, i32* %4
%25 = uitofp i32 %24 to double
%26 = fdiv double %23, %25
br label %45
27: ; preds = %15, %18, %12, %1
%28 = call i64 @acpi_get_property(i8* %6, i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %45, label %30
30: ; preds = %27
%31 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %45
33: ; preds = %30
%34 = call i64 @acpi_get_property(i8* %7, i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %33
%37 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%38 = icmp eq i32 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %36
%40 = load i32, i32* %5
%41 = uitofp i32 %40 to double
%42 = load i32, i32* %4
%43 = uitofp i32 %42 to double
%44 = fdiv double %41, %43
br label %45
45: ; preds = %27, %30, %36, %33, %39, %21
%46 = phi double [ %26, %21 ], [ %44, %39 ], [ 0.000000e+00, %33 ], [ 0.000000e+00, %36 ], [ 0.000000e+00, %30 ], [ 0.000000e+00, %27 ]
ret double %46
}