#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 /*<<< orphan*/ FILE;

/* Variables and functions */
float atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, float);
int /*<<< orphan*/ strncat(char *, char *, size_t);
int bateria(char *b, size_t s) {
  char buffer[500];
  buffer[0] = '\x0';
  FILE *arquivo;
  char *linha;
  char buff[500];
  buff[0] = '\x0';
  float valor;
  arquivo = fopen("/sys/class/power_supply/BAT0/charge_full", "r");
  if (arquivo == 0)
    arquivo = fopen("/sys/class/power_supply/BAT0/energy_full", "r");
  if (arquivo == 0) {
    strncat(b, "<br><p>Dispositivo Desktop</p>", s);
    return -1;
  }
  while (!feof(arquivo)) {
    linha = fgets(buff, 500, arquivo);
    if (linha != 0) {
      valor = atoi(linha);
    }
  }
  fclose(arquivo);
  arquivo = fopen("/sys/class/power_supply/BAT0/charge_now", "r");
  if (arquivo == 0)
    arquivo = fopen("/sys/class/power_supply/BAT0/energy_now", "r");
  if (arquivo == 0) {
    strncat(b, "O arquivo _now nao pode ser lido", s);
    return -1;
  }
  while (!feof(arquivo)) {
    linha = fgets(buff, 500, arquivo);
    if (linha != 0) {
      valor = atoi(linha) / valor * 100;
    }
  }
  fclose(arquivo);
  snprintf(buffer, 500, "<p><b>Battery:</b> %.0f%%</p>", valor);
  strncat(b, buffer, s);
  return 1;
}


x86 assembly (clang, -O0):
<bateria>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,-0x210(%rbp)
movb   $0x0,-0x420(%rbp)
lea    0xe6c(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11d3 <bateria+0x63>
lea    0xe6f(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    1201 <bateria+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe68(%rip),%rsi
call   1050 <strncat@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <bateria+0x240>
jmp    1206 <bateria+0x96>
mov    -0x218(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1227 <bateria+0xb7>
jmp    126d <bateria+0xfd>
lea    -0x420(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x1f4,%esi
call   1060 <fgets@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     1268 <bateria+0xf8>
mov    -0x220(%rbp),%rdi
call   1090 <atoi@plt>
movss  %xmm0,-0x424(%rbp)
ff
jmp    1206 <bateria+0x96>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdf7(%rip),%rdi
lea    0xda6(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    12bb <bateria+0x14b>
lea    0xdf7(%rip),%rdi
lea    0xd7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    12e9 <bateria+0x179>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdef(%rip),%rsi
call   1050 <strncat@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <bateria+0x240>
jmp    12ee <bateria+0x17e>
mov    -0x218(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    130f <bateria+0x19f>
jmp    1369 <bateria+0x1f9>
lea    -0x420(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x1f4,%esi
call   1060 <fgets@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
je     1364 <bateria+0x1f4>
mov    -0x220(%rbp),%rdi
call   1090 <atoi@plt>
divss  -0x424(%rbp),%xmm0
ff
movss  0xca8(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x424(%rbp)
ff
jmp    12ee <bateria+0x17e>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x210(%rbp),%rdi
movss  -0x424(%rbp),%xmm0
ff
mov    $0x1f4,%esi
lea    0xd58(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <strncat@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bateria>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movb   $0x0,0x210(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xe6c(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11cb <bateria+0x5b>
lea    0xe7c(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1303 <bateria+0x193>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     126f <bateria+0xff>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe8d(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    121d <bateria+0xad>
lea    0xe9a(%rip),%rdi
lea    0xe21(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     130c <bateria+0x19c>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     12b5 <bateria+0x145>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xeac(%rip),%rdx
lea    0x210(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1f4,%esi
movss  0xc(%rsp),%xmm0
call   1040 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <strncat@plt>
mov    $0x1,%eax
jmp    1323 <bateria+0x1b3>
lea    0x10(%rsp),%r12
jmp    1290 <bateria+0x120>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11db <bateria+0x6b>
mov    %r12,%rdi
mov    $0x1f4,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1280 <bateria+0x110>
mov    %rax,%rdi
call   1090 <atoi@plt>
movss  %xmm0,0xc(%rsp)
jmp    1280 <bateria+0x110>
lea    0x10(%rsp),%r12
jmp    12d0 <bateria+0x160>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    122d <bateria+0xbd>
mov    %r12,%rdi
mov    $0x1f4,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12c0 <bateria+0x150>
mov    %rax,%rdi
call   1090 <atoi@plt>
divss  0xc(%rsp),%xmm0
mulss  0xd05(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
jmp    12c0 <bateria+0x150>
lea    0xd4e(%rip),%rsi
jmp    1313 <bateria+0x1a3>
lea    0xdb4(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <strncat@plt>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/class/power_supply/BAT0/charge_full\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [41 x i8] c"/sys/class/power_supply/BAT0/energy_full\00"
@.str.3 = [31 x i8] c"<br><p>Dispositivo Desktop</p>\00"
@.str.4 = [40 x i8] c"/sys/class/power_supply/BAT0/charge_now\00"
@.str.5 = [40 x i8] c"/sys/class/power_supply/BAT0/energy_now\00"
@.str.6 = [33 x i8] c"O arquivo _now nao pode ser lido\00"
@.str.7 = [30 x i8] c"<p><b>Battery:</b> %.0f%%</p>\00"
define i32 @bateria(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [500 x i8]
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [500 x i8]
%10 = alloca float
store i8* %0, i8** %4
store i64 %1, i64* %5
%11 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
store i8 0, i8* %11
%12 = getelementptr inbounds [500 x i8], [500 x i8]* %9, i64 0, i64 0
store i8 0, i8* %12
%13 = call i32* @fopen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32* @fopen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %7
br label %18
18: ; preds = %16, %2
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8*, i8** %4
%23 = load i64, i64* %5
%24 = call i32 @strncat(i8* %22, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %23)
store i32 -1, i32* %3
br label %85
25: ; preds = %18
br label %26
26: ; preds = %40, %25
%27 = load i32*, i32** %7
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %41
31: ; preds = %26
%32 = getelementptr inbounds [500 x i8], [500 x i8]* %9, i64 0, i64 0
%33 = load i32*, i32** %7
%34 = call i8* @fgets(i8* %32, i32 500, i32* %33)
store i8* %34, i8** %8
%35 = load i8*, i8** %8
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i8*, i8** %8
%39 = call float @atoi(i8* %38)
store float %39, float* %10
br label %40
40: ; preds = %37, %31
br label %26
41: ; preds = %26
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
%44 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %44, i32** %7
%45 = load i32*, i32** %7
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %48, i32** %7
br label %49
49: ; preds = %47, %41
%50 = load i32*, i32** %7
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i8*, i8** %4
%54 = load i64, i64* %5
%55 = call i32 @strncat(i8* %53, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i64 %54)
store i32 -1, i32* %3
br label %85
56: ; preds = %49
br label %57
57: ; preds = %74, %56
%58 = load i32*, i32** %7
%59 = call i32 @feof(i32* %58)
%60 = icmp ne i32 %59, 0
%61 = xor i1 %60, true
br i1 %61, label %62, label %75
62: ; preds = %57
%63 = getelementptr inbounds [500 x i8], [500 x i8]* %9, i64 0, i64 0
%64 = load i32*, i32** %7
%65 = call i8* @fgets(i8* %63, i32 500, i32* %64)
store i8* %65, i8** %8
%66 = load i8*, i8** %8
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %74
68: ; preds = %62
%69 = load i8*, i8** %8
%70 = call float @atoi(i8* %69)
%71 = load float, float* %10
%72 = fdiv float %70, %71
%73 = fmul float %72, 1.000000e+02
store float %73, float* %10
br label %74
74: ; preds = %68, %62
br label %57
75: ; preds = %57
%76 = load i32*, i32** %7
%77 = call i32 @fclose(i32* %76)
%78 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%79 = load float, float* %10
%80 = call i32 @snprintf(i8* %78, i32 500, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), float %79)
%81 = load i8*, i8** %4
%82 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%83 = load i64, i64* %5
%84 = call i32 @strncat(i8* %81, i8* %82, i64 %83)
store i32 1, i32* %3
br label %85
85: ; preds = %75, %52, %21
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/class/power_supply/BAT0/charge_full\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [41 x i8] c"/sys/class/power_supply/BAT0/energy_full\00"
@.str.3 = [31 x i8] c"<br><p>Dispositivo Desktop</p>\00"
@.str.4 = [40 x i8] c"/sys/class/power_supply/BAT0/charge_now\00"
@.str.5 = [40 x i8] c"/sys/class/power_supply/BAT0/energy_now\00"
@.str.6 = [33 x i8] c"O arquivo _now nao pode ser lido\00"
@.str.7 = [30 x i8] c"<p><b>Battery:</b> %.0f%%</p>\00"
define i32 @bateria(i8* %0, i64 %1) {
%3 = alloca [500 x i8]
%4 = alloca [500 x i8]
%5 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
store i8 0, i8* %5
%6 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
store i8 0, i8* %6
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2, %9
%13 = phi i32* [ %10, %9 ], [ %7, %2 ]
%14 = call i32 @feof(i32* %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %28
16: ; preds = %9
%17 = tail call i32 @strncat(i8* %0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %1)
br label %59
18: ; preds = %12, %24
%19 = phi float [ %25, %24 ], [ undef, %12 ]
%20 = call i8* @fgets(i8* %6, i32 500, i32* %13)
%21 = icmp eq i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = call float @atoi(i8* %20)
br label %24
24: ; preds = %22, %18
%25 = phi float [ %23, %22 ], [ %19, %18 ]
%26 = call i32 @feof(i32* %13)
%27 = icmp eq i32 %26, 0
br i1 %27, label %18, label %28
28: ; preds = %24, %12
%29 = phi float [ undef, %12 ], [ %25, %24 ]
%30 = call i32 @fclose(i32* %13)
%31 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %40, label %36
36: ; preds = %28, %33
%37 = phi i32* [ %34, %33 ], [ %31, %28 ]
%38 = call i32 @feof(i32* %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %42, label %54
40: ; preds = %33
%41 = call i32 @strncat(i8* %0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i64 %1)
br label %59
42: ; preds = %36, %50
%43 = phi float [ %51, %50 ], [ %29, %36 ]
%44 = call i8* @fgets(i8* %6, i32 500, i32* %37)
%45 = icmp eq i8* %44, null
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = call float @atoi(i8* %44)
%48 = fdiv float %47, %43
%49 = fmul float %48, 1.000000e+02
br label %50
50: ; preds = %46, %42
%51 = phi float [ %49, %46 ], [ %43, %42 ]
%52 = call i32 @feof(i32* %37)
%53 = icmp eq i32 %52, 0
br i1 %53, label %42, label %54
54: ; preds = %50, %36
%55 = phi float [ %29, %36 ], [ %51, %50 ]
%56 = call i32 @fclose(i32* %37)
%57 = call i32 @snprintf(i8* %5, i32 500, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), float %55)
%58 = call i32 @strncat(i8* %0, i8* %5, i64 %1)
br label %59
59: ; preds = %54, %40, %16
%60 = phi i32 [ -1, %16 ], [ -1, %40 ], [ 1, %54 ]
ret i32 %60
}