#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 *);
int /*<<< orphan*/ strcpy(char *, char *);
void get_ac_status(char *bs) {
  FILE *file;
  int ac_online;
  if ((file = fopen("/sys/class/power_supply/AC0/online", "r")) == NULL) {
    strcpy(bs, "¿?");
    return;
  }
  fscanf(file, "%d", &ac_online);
  fclose(file);
  if (ac_online)
    strcpy(bs, "Ac");
  else
    strcpy(bs, "Bat");
}


x86 assembly (clang, -O0):
<get_ac_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1182 <get_ac_status+0x42>
mov    -0x8(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11ce <get_ac_status+0x8e>
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x14(%rbp)
je     11be <get_ac_status+0x7e>
mov    -0x8(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11ce <get_ac_status+0x8e>
mov    -0x8(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ac_status>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0xece(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118e <get_ac_status+0x4e>
mov    %rax,%rbx
lea    0xec0(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
cmpl   $0x0,0x4(%rsp)
je     11a4 <get_ac_status+0x64>
lea    0xea0(%rip),%rsi
jmp    11ab <get_ac_status+0x6b>
lea    0xe90(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>
lea    0xe84(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c"/sys/class/power_supply/AC0/online\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"\C2\BF?\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c"Ac\00"
@.str.5 = [4 x i8] c"Bat\00"
define void @get_ac_status(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %23
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%13 = load i32*, i32** %3
%14 = call i32 @fclose(i32* %13)
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %23
20: ; preds = %10
%21 = load i8*, i8** %2
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %7, %20, %17
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"/sys/class/power_supply/AC0/online\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"\C2\BF?\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c"Ac\00"
@.str.5 = [4 x i8] c"Bat\00"
define void @get_ac_status(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %17
8: ; preds = %1
%9 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%10 = call i32 @fclose(i32* %4)
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %17
15: ; preds = %8
%16 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %13, %15, %6
ret void
}