#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 *);
int prefix_forwarding_enabled() {
  char returnCode;
  int router = 0;
  FILE *f = fopen("/proc/sys/net/ipv6/conf/all/forwarding", "r");
  if (f) {
    returnCode = fgetc(f);
    if (returnCode == '1')
      router = 1;
  }
  fclose(f);
  return router;
}


x86 assembly (clang, -O0):
<prefix_forwarding_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xeba(%rip),%rdi
lea    0xeda(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1186 <prefix_forwarding_enabled+0x56>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x31,%eax
jne    1181 <prefix_forwarding_enabled+0x51>
movl   $0x1,-0x8(%rbp)
jmp    1186 <prefix_forwarding_enabled+0x56>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prefix_forwarding_enabled>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
lea    0xee6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1160 <prefix_forwarding_enabled+0x30>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
xor    %ebp,%ebp
cmp    $0x31,%al
sete   %bpl
jmp    1162 <prefix_forwarding_enabled+0x32>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"/proc/sys/net/ipv6/conf/all/forwarding\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @prefix_forwarding_enabled() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 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** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %15
7: ; preds = %0
%8 = load i32*, i32** %3
%9 = call signext i8 @fgetc(i32* %8)
store i8 %9, i8* %1
%10 = load i8, i8* %1
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 49
br i1 %12, label %13, label %14
13: ; preds = %7
store i32 1, i32* %2
br label %14
14: ; preds = %13, %7
br label %15
15: ; preds = %14, %0
%16 = load i32*, i32** %3
%17 = call i32 @fclose(i32* %16)
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@.str = [39 x i8] c"/proc/sys/net/ipv6/conf/all/forwarding\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @prefix_forwarding_enabled() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([39 x i8], [39 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 %7, label %3
3: ; preds = %0
%4 = tail call signext i8 @fgetc(i32* %1)
%5 = icmp eq i8 %4, 49
%6 = zext i1 %5 to i32
br label %7
7: ; preds = %3, %0
%8 = phi i32 [ 0, %0 ], [ %6, %3 ]
%9 = tail call i32 @fclose(i32* %1)
ret i32 %8
}