#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char get_status() {
  FILE *fp;
  char st;
  if ((fp = fopen("/sys/class/power_supply/BAT0/status", "r")) == NULL)
    return '?';
  st = fgetc(fp);
  fclose(fp);
  switch (st) {
  case 'C':
    return '+';
  case 'D':
    return '-';
  case 'F':
    return '=';
  default:
    return '?';
  }
}


x86 assembly (clang, -O0):
<get_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
lea    0xede(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1162 <get_status+0x32>
movb   $0x3f,-0x1(%rbp)
jmp    11cd <get_status+0x9d>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x43,%eax
je     11ae <get_status+0x7e>
jmp    118c <get_status+0x5c>
mov    -0x18(%rbp),%eax
sub    $0x44,%eax
je     11b7 <get_status+0x87>
jmp    119d <get_status+0x6d>
mov    -0x18(%rbp),%eax
sub    $0x46,%eax
je     11c0 <get_status+0x90>
jmp    11c9 <get_status+0x99>
movb   $0x2b,-0x1(%rbp)
jmp    11cd <get_status+0x9d>
movb   $0x2d,-0x1(%rbp)
jmp    11cd <get_status+0x9d>
movb   $0x3d,-0x1(%rbp)
jmp    11cd <get_status+0x9d>
movb   $0x3f,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_status>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%rdi
lea    0xee2(%rip),%rsi
call   1050 <fopen@plt>
mov    $0x3f,%bpl
test   %rax,%rax
je     117b <get_status+0x4b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
movsbl %r14b,%ecx
add    $0xffffffbd,%ecx
cmp    $0x3,%ecx
ja     117b <get_status+0x4b>
shl    $0x3,%ecx
mov    $0x3d3f2d2b,%ebp
shr    %cl,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"/sys/class/power_supply/BAT0/status\00"
@.str.1 = [2 x i8] c"r\00"
define signext i8 @get_status() {
%1 = alloca i8
%2 = alloca i32*
%3 = alloca i8
%4 = call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %0
store i8 63, i8* %1
br label %18
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = call signext i8 @fgetc(i32* %8)
store i8 %9, i8* %3
%10 = load i32*, i32** %2
%11 = call i32 @fclose(i32* %10)
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
switch i32 %13, label %17 [
i32 67, label %14
i32 68, label %15
i32 70, label %16
]
14: ; preds = %7
store i8 43, i8* %1
br label %18
15: ; preds = %7
store i8 45, i8* %1
br label %18
16: ; preds = %7
store i8 61, i8* %1
br label %18
17: ; preds = %7
store i8 63, i8* %1
br label %18
18: ; preds = %17, %16, %15, %14, %6
%19 = load i8, i8* %1
ret i8 %19
}

LLVM IR (-O2):
@.str = [36 x i8] c"/sys/class/power_supply/BAT0/status\00"
@.str.1 = [2 x i8] c"r\00"
define signext i8 @get_status() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = tail call signext i8 @fgetc(i32* %1)
%5 = tail call i32 @fclose(i32* %1)
%6 = sext i8 %4 to i32
%7 = add nsw i32 %6, -67
%8 = icmp ult i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = shl nsw i32 %7, 3
%11 = lshr i32 1027550507, %10
%12 = trunc i32 %11 to i8
br label %13
13: ; preds = %3, %9, %0
%14 = phi i8 [ 63, %0 ], [ %12, %9 ], [ 63, %3 ]
ret i8 %14
}