#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 fscanf(int /*<<< orphan*/ *, char *, int *);
int onac(void) {
  FILE *fp;
  int on = 0;
  if ((fp = fopen("/proc/apm", "r"))) {
    int ac = 0;
    if (fscanf(fp, "%*[^ ] %*d.%*d 0x%*x 0x%x 0x%*x 0x%*x %*d%% %*i %*c",
               &ac) == 1)
      on = (ac == 0x01) ? 1 : 0;
    fclose(fp);
  }
  return on;
}


x86 assembly (clang, -O0):
<onac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11a0 <onac+0x70>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9a(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1197 <onac+0x67>
mov    -0x10(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<onac>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1186 <onac+0x56>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
lea    0xeaf(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
xor    $0x1,%eax
mov    0x4(%rsp),%ecx
xor    $0x1,%ecx
xor    %ebp,%ebp
or     %eax,%ecx
sete   %bpl
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1188 <onac+0x58>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/proc/apm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [52 x i8] c"%*[^ ] %*d.%*d 0x%*x 0x%x 0x%*x 0x%*x %*d%% %*i %*c\00"
define i32 @onac() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %6, label %18
6: ; preds = %0
store i32 0, i32* %3
%7 = load i32*, i32** %1
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 1
%13 = zext i1 %12 to i64
%14 = select i1 %12, i32 1, i32 0
store i32 %14, i32* %2
br label %15
15: ; preds = %10, %6
%16 = load i32*, i32** %1
%17 = call i32 @fclose(i32* %16)
br label %18
18: ; preds = %15, %0
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@.str = [10 x i8] c"/proc/apm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [52 x i8] c"%*[^ ] %*d.%*d 0x%*x 0x%x 0x%*x 0x%*x %*d%% %*i %*c\00"
define i32 @onac() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %13, label %4
4: ; preds = %0
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 1
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 1
%10 = select i1 %7, i1 %9, i1 false
%11 = zext i1 %10 to i32
%12 = call i32 @fclose(i32* %2)
br label %13
13: ; preds = %4, %0
%14 = phi i32 [ %11, %4 ], [ 0, %0 ]
ret i32 %14
}