#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *battery(void) {
  int nmarks, full, now;
  char *bar;
  FILE *battinfo = fopen("/sys/class/power_supply/BAT1/energy_full", "r");
  fscanf(battinfo, "%d", &full);
  fclose(battinfo);
  battinfo = fopen("/sys/class/power_supply/BAT1/energy_now", "r");
  fscanf(battinfo, "%d", &now);
  fclose(battinfo);
  bar = (char *)malloc(sizeof(char) * 25);
  nmarks = 10 * now / full;
  if ((double)now / full <= 0.05) {
    strcpy(bar, "*** BATTERIE < 5% ***");
  } else {
    strcpy(bar, "[");
    for (int i = 1; i < 11; i++) {
      if (i <= nmarks)
        strcat(bar, "#");
      else
        strcat(bar, " ");
    }
    strcat(bar, "]");
  }
  return bar;
}


x86 assembly (clang, -O0):
<battery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe99(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xea9(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe93(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe75(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x19,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
imul   $0xa,-0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x4(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe01(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     121e <battery+0xbe>
mov    -0x18(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1293 <battery+0x133>
mov    -0x18(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x24(%rbp)
cmpl   $0xb,-0x24(%rbp)
jge    1283 <battery+0x123>
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1260 <battery+0x100>
mov    -0x18(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1080 <strcat@plt>
jmp    1270 <battery+0x110>
mov    -0x18(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1080 <strcat@plt>
jmp    1275 <battery+0x115>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1235 <battery+0xd5>
mov    -0x18(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<battery>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe99(%rip),%rdi
lea    0xebb(%rip),%rbx
mov    %rbx,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
lea    0xeab(%rip),%r14
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <fscanf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xe8f(%rip),%rdi
mov    %rbx,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x19,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%ecx
lea    (%rcx,%rcx,1),%eax
lea    (%rax,%rax,4),%eax
mov    0xc(%rsp),%esi
cltd
idiv   %esi
cvtsi2sd %ecx,%xmm0
cvtsi2sd %esi,%xmm1
divsd  %xmm1,%xmm0
movsd  0xe04(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    1306 <battery+0x1a6>
mov    %eax,%r14d
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
test   %r14d,%r14d
jle    131a <battery+0x1ba>
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
cmp    $0x1,%r14d
je     1329 <battery+0x1c9>
lea    0xe35(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
cmp    $0x2,%r14d
jbe    1338 <battery+0x1d8>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
cmp    $0x3,%r14d
je     1347 <battery+0x1e7>
lea    0xe03(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
cmp    $0x4,%r14d
jbe    1356 <battery+0x1f6>
lea    0xdea(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
cmp    $0x5,%r14d
je     1365 <battery+0x205>
lea    0xdd1(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
cmp    $0x6,%r14d
jbe    1374 <battery+0x214>
lea    0xdb8(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
cmp    $0x7,%r14d
je     1383 <battery+0x223>
lea    0xd9f(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcat@plt>
cmp    $0x8,%r14d
jbe    1392 <battery+0x232>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcat@plt>
cmp    $0x9,%r14d
je     13a1 <battery+0x241>
jmp    13a8 <battery+0x248>
lea    0xd51(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    13c2 <battery+0x262>
lea    0xd57(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xd48(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xd39(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xd2a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xd1b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xd0c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xcfd(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xcee(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xcdf(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xcd0(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcat@plt>
lea    0xcc0(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/class/power_supply/BAT1/energy_full\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [40 x i8] c"/sys/class/power_supply/BAT1/energy_now\00"
@.str.4 = [22 x i8] c"*** BATTERIE < 5% ***\00"
@.str.5 = [2 x i8] c"[\00"
@.str.6 = [2 x i8] c"#\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [2 x i8] c"]\00"
define i8* @battery() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = 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* %7, i32** %5
%8 = load i32*, i32** %5
%9 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = load i32*, i32** %5
%11 = call i32 @fclose(i32* %10)
%12 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%15 = load i32*, i32** %5
%16 = call i32 @fclose(i32* %15)
%17 = call i64 @malloc(i32 25)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %4
%19 = load i32, i32* %3
%20 = mul nsw i32 10, %19
%21 = load i32, i32* %2
%22 = sdiv i32 %20, %21
store i32 %22, i32* %1
%23 = load i32, i32* %3
%24 = sitofp i32 %23 to double
%25 = load i32, i32* %2
%26 = sitofp i32 %25 to double
%27 = fdiv double %24, %26
%28 = fcmp ole double %27, 5.000000e-02
br i1 %28, label %29, label %32
29: ; preds = %0
%30 = load i8*, i8** %4
%31 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %55
32: ; preds = %0
%33 = load i8*, i8** %4
%34 = call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %6
br label %35
35: ; preds = %49, %32
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 11
br i1 %37, label %38, label %52
38: ; preds = %35
%39 = load i32, i32* %6
%40 = load i32, i32* %1
%41 = icmp sle i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8*, i8** %4
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %48
45: ; preds = %38
%46 = load i8*, i8** %4
%47 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %48
48: ; preds = %45, %42
br label %49
49: ; preds = %48
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %35
52: ; preds = %35
%53 = load i8*, i8** %4
%54 = call i32 @strcat(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %55
55: ; preds = %52, %29
%56 = load i8*, i8** %4
ret i8* %56
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/class/power_supply/BAT1/energy_full\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [40 x i8] c"/sys/class/power_supply/BAT1/energy_now\00"
@.str.4 = [22 x i8] c"*** BATTERIE < 5% ***\00"
@.str.5 = [2 x i8] c"[\00"
@.str.6 = [2 x i8] c"#\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [2 x i8] c"]\00"
define i8* @battery() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = 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))
%6 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = call i32 @fclose(i32* %5)
%8 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = call i32 @fclose(i32* %8)
%11 = call i64 @malloc(i32 25)
%12 = inttoptr i64 %11 to i8*
%13 = load i32, i32* %2
%14 = mul nsw i32 %13, 10
%15 = load i32, i32* %1
%16 = sdiv i32 %14, %15
%17 = sitofp i32 %13 to double
%18 = sitofp i32 %15 to double
%19 = fdiv double %17, %18
%20 = fcmp ugt double %19, 5.000000e-02
br i1 %20, label %23, label %21
21: ; preds = %0
%22 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %76
23: ; preds = %0
%24 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp slt i32 %16, 1
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %31
28: ; preds = %23
%29 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i32 %16, 1
br i1 %30, label %31, label %33
31: ; preds = %28, %26
%32 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %36
33: ; preds = %28
%34 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%35 = icmp ult i32 %16, 3
br i1 %35, label %36, label %38
36: ; preds = %33, %31
%37 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %41
38: ; preds = %33
%39 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%40 = icmp eq i32 %16, 3
br i1 %40, label %41, label %43
41: ; preds = %38, %36
%42 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %46
43: ; preds = %38
%44 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%45 = icmp ult i32 %16, 5
br i1 %45, label %46, label %48
46: ; preds = %43, %41
%47 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %51
48: ; preds = %43
%49 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%50 = icmp eq i32 %16, 5
br i1 %50, label %51, label %53
51: ; preds = %48, %46
%52 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %56
53: ; preds = %48
%54 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%55 = icmp ult i32 %16, 7
br i1 %55, label %56, label %58
56: ; preds = %53, %51
%57 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %61
58: ; preds = %53
%59 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%60 = icmp eq i32 %16, 7
br i1 %60, label %61, label %63
61: ; preds = %58, %56
%62 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %66
63: ; preds = %58
%64 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%65 = icmp ult i32 %16, 9
br i1 %65, label %66, label %68
66: ; preds = %63, %61
%67 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %71
68: ; preds = %63
%69 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%70 = icmp eq i32 %16, 9
br i1 %70, label %71, label %72
71: ; preds = %66, %68
br label %72
72: ; preds = %68, %71
%73 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), %71 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), %68 ]
%74 = call i32 @strcat(i8* %12, i8* %73)
%75 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %76
76: ; preds = %72, %21
ret i8* %12
}