#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
bool get_autoflowlabel_enabled(void) {
  int fd, ret;
  char val;
  fd = open("/proc/sys/net/ipv6/auto_flowlabels", O_RDONLY);
  if (fd == -1)
    error(1, errno, "open sysctl");
  ret = read(fd, &val, 1);
  if (ret == -1)
    error(1, errno, "read sysctl");
  if (ret == 0)
    error(1, 0, "read sysctl: 0");
  if (close(fd))
    error(1, errno, "close sysctl");
  return val == '1';
}


x86 assembly (clang, -O0):
<get_autoflowlabel_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1184 <get_autoflowlabel_enabled+0x44>
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xea4(%rip),%rdx
call   1050 <error@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11bc <get_autoflowlabel_enabled+0x7c>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe78(%rip),%rdx
call   1050 <error@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11d9 <get_autoflowlabel_enabled+0x99>
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe67(%rip),%rdx
call   1050 <error@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
je     1205 <get_autoflowlabel_enabled+0xc5>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe4a(%rip),%rdx
call   1050 <error@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x31,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_autoflowlabel_enabled>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117b <get_autoflowlabel_enabled+0x3b>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xeb2(%rip),%rdx
mov    $0x1,%edi
call   1050 <error@plt>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
je     11ac <get_autoflowlabel_enabled+0x6c>
cmp    $0xffffffff,%eax
jne    11bf <get_autoflowlabel_enabled+0x7f>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdx
mov    $0x1,%edi
jmp    11ba <get_autoflowlabel_enabled+0x7a>
lea    0xe88(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <error@plt>
mov    %ebx,%edi
call   1030 <close@plt>
test   %rax,%rax
je     11e5 <get_autoflowlabel_enabled+0xa5>
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdx
mov    $0x1,%edi
call   1050 <error@plt>
xor    %eax,%eax
cmpb   $0x31,0xf(%rsp)
sete   %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"/proc/sys/net/ipv6/auto_flowlabels\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.1 = [12 x i8] c"open sysctl\00"
@.str.2 = [12 x i8] c"read sysctl\00"
@.str.3 = [15 x i8] c"read sysctl: 0\00"
@.str.4 = [13 x i8] c"close sysctl\00"
define i32 @get_autoflowlabel_enabled() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = call i32 @error(i32 1, i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %8, %0
%12 = load i32, i32* %1
%13 = call i32 @read(i32 %12, i8* %3, i32 1)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = call i32 @error(i32 1, i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %16, %11
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* %1
%26 = call i64 @close(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @errno
%30 = call i32 @error(i32 1, i32 %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %28, %24
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 49
%35 = zext i1 %34 to i32
ret i32 %35
}

LLVM IR (-O2):
@.str = [35 x i8] c"/proc/sys/net/ipv6/auto_flowlabels\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.1 = [12 x i8] c"open sysctl\00"
@.str.2 = [12 x i8] c"read sysctl\00"
@.str.3 = [15 x i8] c"read sysctl: 0\00"
@.str.4 = [13 x i8] c"close sysctl\00"
define i32 @get_autoflowlabel_enabled() {
%1 = alloca i8
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = tail call i32 @error(i32 1, i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = call i32 @read(i32 %3, i8* %1, i32 1)
switch i32 %9, label %15 [
i32 -1, label %10
i32 0, label %13
]
10: ; preds = %8
%11 = load i32, i32* @errno
%12 = tail call i32 @error(i32 1, i32 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %15
13: ; preds = %8
%14 = tail call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %10, %8, %13
%16 = tail call i64 @close(i32 %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* @errno
%20 = tail call i32 @error(i32 1, i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %18, %15
%22 = load i8, i8* %1
%23 = icmp eq i8 %22, 49
%24 = zext i1 %23 to i32
ret i32 %24
}