#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*/ disable_csum();
int /*<<< orphan*/ enable_csum();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int toggle_csum() {
  int res, current;
  FILE *f = fopen("/proc/sys/net/mptcp/mptcp_checksum", "r");
  current = fgetc(f);
  fclose(f);
  printf("before-change value is %c\n", current);
  if (current == 48) {
    enable_csum();
  } else {
    disable_csum();
  }
}


x86 assembly (clang, -O0):
<toggle_csum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xead(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%esi
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x30,-0xc(%rbp)
jne    11b9 <toggle_csum+0x59>
mov    $0x0,%al
call   1080 <enable_csum@plt>
jmp    11c0 <toggle_csum+0x60>
mov    $0x0,%al
call   1060 <disable_csum@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toggle_csum>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe93(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
cmp    $0x30,%ebp
jne    11a7 <toggle_csum+0x47>
call   1080 <enable_csum@plt>
jmp    11ac <toggle_csum+0x4c>
call   1060 <disable_csum@plt>
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"r\00"
@.str.2 = [27 x i8] c"before-change value is %c\0A\00"
define i32 @toggle_csum() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%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** %4
%6 = load i32*, i32** %4
%7 = call i32 @fgetc(i32* %6)
store i32 %7, i32* %3
%8 = load i32*, i32** %4
%9 = call i32 @fclose(i32* %8)
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 48
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (...) @enable_csum()
br label %18
16: ; preds = %0
%17 = call i32 (...) @disable_csum()
br label %18
18: ; preds = %16, %14
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [35 x i8] c"/proc/sys/net/mptcp/mptcp_checksum\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"before-change value is %c\0A\00"
define i32 @toggle_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 = tail call i32 @fgetc(i32* %1)
%3 = tail call i32 @fclose(i32* %1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%5 = icmp eq i32 %2, 48
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 (...) @enable_csum()
br label %10
8: ; preds = %0
%9 = tail call i32 (...) @disable_csum()
br label %10
10: ; preds = %8, %6
ret i32 undef
}