#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 /*<<< orphan*/ sprintf(char *, char *, char const *);
int write(int, char *, int);
int linux_icmp_redirect_off(const char *iface) {
  char fname[256];
  int fd, ret = -1;
  sprintf(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    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x118(%rbp)
ff ff ff
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe95(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    11a4 <linux_icmp_redirect_off+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <linux_icmp_redirect_off+0xa2>
mov    -0x114(%rbp),%edi
lea    0xe79(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmp    $0x2,%eax
jne    11ce <linux_icmp_redirect_off+0x8e>
movl   $0x0,-0x118(%rbp)
mov    -0x114(%rbp),%edi
call   1040 <close@plt>
mov    -0x118(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linux_icmp_redirect_off>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rdx
lea    0xead(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
js     119c <linux_icmp_redirect_off+0x5c>
mov    %eax,%ebx
lea    0xeae(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %ebp,%ebp
cmp    $0x2,%eax
setne  %bpl
neg    %ebp
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11a1 <linux_icmp_redirect_off+0x61>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.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 [256 x i8]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %6
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %25
16: ; preds = %1
%17 = load i32, i32* %5
%18 = call i32 @write(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %6
br label %21
21: ; preds = %20, %16
%22 = load i32, i32* %5
%23 = call i32 @close(i32 %22)
%24 = load i32, i32* %6
store i32 %24, i32* %2
br label %25
25: ; preds = %21, %15
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.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 [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* %3, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%10 = icmp ne i32 %9, 2
%11 = sext i1 %10 to i32
%12 = tail call i32 @close(i32 %6)
br label %13
13: ; preds = %1, %8
%14 = phi i32 [ %11, %8 ], [ -1, %1 ]
ret i32 %14
}