#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 fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *);
int enable_csum() {
  int res;
  FILE *f = fopen("/proc/sys/net/mptcp/mptcp_checksum", "w");
  if (f == NULL) {
    printf("Error opening file! Do you have root powers and is this kernel "
           "mptcp capable?\n");
    return -1;
  }
  res = fprintf(f, "%d", 1);
  fclose(f);
  return res;
}


x86 assembly (clang, -O0):
<enable_csum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xecd(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1182 <enable_csum+0x42>
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <enable_csum+0x69>
mov    -0x10(%rbp),%rdi
lea    0xee7(%rip),%rsi
mov    $0x1,%edx
call   1050 <fprintf@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enable_csum>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
lea    0xed2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1180 <enable_csum+0x40>
mov    %rax,%rbx
lea    0xec0(%rip),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
call   1050 <fprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
jmp    1191 <enable_csum+0x51>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"/proc/sys/net/mptcp/mptcp_checksum\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [79 x i8] c"Error opening file! Do you have root powers and is this kernel mptcp capable?\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @enable_csum() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = 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* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %15
9: ; preds = %0
%10 = load i32*, i32** %3
%11 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 1)
store i32 %11, i32* %2
%12 = load i32*, i32** %3
%13 = call i32 @fclose(i32* %12)
%14 = load i32, i32* %2
store i32 %14, i32* %1
br label %15
15: ; preds = %9, %7
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str = [35 x i8] c"/proc/sys/net/mptcp/mptcp_checksum\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%d\00"
@str = [78 x i8] c"Error opening file! Do you have root powers and is this kernel mptcp capable?\00"
define i32 @enable_csum() {
%1 = 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))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str, i64 0, i64 0))
br label %8
5: ; preds = %0
%6 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 1)
%7 = tail call i32 @fclose(i32* %1)
br label %8
8: ; preds = %5, %3
%9 = phi i32 [ -1, %3 ], [ %6, %5 ]
ret i32 %9
}