#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int write(int, void *, int);
int iproute_flush_cache(void) {
  int len;
  int flush_fd = open("/proc/sys/net/ipv4/route/flush", O_WRONLY);
  char *buffer = "-1";
  if (flush_fd < 0) {
    fprintf(stderr, "Cannot open \"%s\"\n", "/proc/sys/net/ipv4/route/flush");
    return -1;
  }
  len = strlen(buffer);
  if ((write(flush_fd, (void *)buffer, len)) < len) {
    fprintf(stderr, "Cannot flush routing cache\n");
    return -1;
  }
  close(flush_fd);
  return 0;
}


x86 assembly (clang, -O0):
<iproute_flush_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11af <iproute_flush_cache+0x5f>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
lea    0xe64(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <iproute_flush_cache+0xb5>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <write@plt>
cmp    -0x8(%rbp),%eax
jge    11f6 <iproute_flush_cache+0xa6>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <iproute_flush_cache+0xb5>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iproute_flush_cache>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11ae <iproute_flush_cache+0x5e>
mov    %eax,%ebx
lea    0xea9(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
jge    11d3 <iproute_flush_cache+0x83>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11dc <iproute_flush_cache+0x8c>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
lea    0xe3b(%rip),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11dc <iproute_flush_cache+0x8c>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"/proc/sys/net/ipv4/route/flush\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"-1\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Cannot open \22%s\22\0A\00"
@.str.3 = [28 x i8] c"Cannot flush routing cache\0A\00"
define i32 @iproute_flush_cache() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %4
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %27
12: ; preds = %0
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %2
%15 = load i32, i32* %3
%16 = load i8*, i8** %4
%17 = load i32, i32* %2
%18 = call i32 @write(i32 %15, i8* %16, i32 %17)
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %27
24: ; preds = %12
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
store i32 0, i32* %1
br label %27
27: ; preds = %24, %21, %9
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [31 x i8] c"/proc/sys/net/ipv4/route/flush\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"-1\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Cannot open \22%s\22\0A\00"
@.str.3 = [28 x i8] c"Cannot flush routing cache\0A\00"
define i32 @iproute_flush_cache() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %16
7: ; preds = %0
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, %8
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %16
14: ; preds = %7
%15 = tail call i32 @close(i32 %2)
br label %16
16: ; preds = %14, %11, %4
%17 = phi i32 [ -1, %4 ], [ -1, %11 ], [ 0, %14 ]
ret i32 %17
}