#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_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int write(int, char *, int);
int toggle_kernel_auto_icmp_reply(int yes) {
  int fd = open("/proc/sys/net/ipv4/icmp_echo_ignore_all", O_WRONLY);
  if (fd == -1) {
    return 0;
  }
  int res = write(fd, (yes == 1 ? "0" : "1"), 1);
  close(fd);
  if (res == -1) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<toggle_kernel_auto_icmp_reply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1169 <toggle_kernel_auto_icmp_reply+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <toggle_kernel_auto_icmp_reply+0x86>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%ecx
lea    0xeb4(%rip),%rsi
lea    0xeab(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    11af <toggle_kernel_auto_icmp_reply+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <toggle_kernel_auto_icmp_reply+0x86>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toggle_kernel_auto_icmp_reply>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xebb(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1185 <toggle_kernel_auto_icmp_reply+0x55>
mov    %eax,%ebx
cmp    $0x1,%ebp
lea    0xecd(%rip),%rax
lea    0xec8(%rip),%rsi
cmove  %rax,%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebp
setne  %al
jmp    1187 <toggle_kernel_auto_icmp_reply+0x57>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"/proc/sys/net/ipv4/icmp_echo_ignore_all\00"
@O_WRONLY = global i32 0
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c"1\00"
define i32 @toggle_kernel_auto_icmp_reply(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %24
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 1
%15 = zext i1 %14 to i64
%16 = select i1 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%17 = call i32 @write(i32 %12, i8* %16, i32 1)
store i32 %17, i32* %5
%18 = load i32, i32* %4
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %11
store i32 0, i32* %2
br label %24
23: ; preds = %11
store i32 1, i32* %2
br label %24
24: ; preds = %23, %22, %10
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [40 x i8] c"/proc/sys/net/ipv4/icmp_echo_ignore_all\00"
@O_WRONLY = global i32 0
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c"1\00"
define i32 @toggle_kernel_auto_icmp_reply(i32 %0) {
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = icmp eq i32 %0, 1
%7 = select i1 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%8 = tail call i32 @write(i32 %3, i8* %7, i32 1)
%9 = tail call i32 @close(i32 %3)
%10 = icmp ne i32 %8, -1
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %1, %5
%13 = phi i32 [ %11, %5 ], [ 0, %1 ]
ret i32 %13
}