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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int write(int, char *, int);
int linux_icmp_redirect_off(const char *iface) {
  char fname[PATH_MAX];
  int fd, ret = -1;
  snprintf(fname, sizeof(fname), "/proc/sys/net/ipv4/conf/%s/send_redirects",
           iface);
  fd = open(fname, O_WRONLY);
  if (fd < 0)
    return -1;
  if (write(fd, "0\n", 2) == 2)
    ret = 0;
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<linux_icmp_redirect_off>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movl   $0xffffffff,-0x28(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe74(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x38(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11c3 <linux_icmp_redirect_off+0x83>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11fc <linux_icmp_redirect_off+0xbc>
mov    -0x24(%rbp),%edi
lea    0xe5d(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
jne    11e7 <linux_icmp_redirect_off+0xa7>
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linux_icmp_redirect_off>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%rcx
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe92(%rip),%rdx
mov    %rbx,%rdi
call   1040 <snprintf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11b5 <linux_icmp_redirect_off+0x75>
mov    %eax,%r14d
lea    0xe95(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
cmp    $0x2,%eax
setne  %bl
neg    %ebx
mov    %r14d,%edi
call   1050 <close@plt>
jmp    11ba <linux_icmp_redirect_off+0x7a>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [42 x i8] c"/proc/sys/net/ipv4/conf/%s/send_redirects\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"0\0A\00"
define i32 @linux_icmp_redirect_off(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
store i32 -1, i32* %7
%13 = trunc i64 %10 to i32
%14 = load i8*, i8** %3
%15 = call i32 @snprintf(i8* %12, i32 %13, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @O_WRONLY
%17 = call i32 @open(i8* %12, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %1
store i32 -1, i32* %2
store i32 1, i32* %8
br label %30
21: ; preds = %1
%22 = load i32, i32* %6
%23 = call i32 @write(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %7
br label %26
26: ; preds = %25, %21
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %7
store i32 %29, i32* %2
store i32 1, i32* %8
br label %30
30: ; preds = %26, %20
%31 = load i8*, i8** %4
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [42 x i8] c"/proc/sys/net/ipv4/conf/%s/send_redirects\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"0\0A\00"
define i32 @linux_icmp_redirect_off(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @snprintf(i8* %4, i32 %2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* %4, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = call i32 @write(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%11 = icmp ne i32 %10, 2
%12 = sext i1 %11 to i32
%13 = call i32 @close(i32 %7)
br label %14
14: ; preds = %1, %9
%15 = phi i32 [ %12, %9 ], [ -1, %1 ]
ret i32 %15
}