#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*/ in_addr_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ net_del_gateway(int /*<<< orphan*/);
scalar_t__ net_search_gateway(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int net_clean_gateway(void) {
  in_addr_t gate_addr;
  char buff[132];
  FILE *fp = fopen("/proc/net/route", "r");
  if (!fp) {
    perror("/proc/net/route");
    printf("INET (IPv4) not configured in this system.\n");
    return -1;
  }
  fgets(buff, 130, fp);
  while (fgets(buff, 130, fp) != NULL) {
    if (net_search_gateway(buff, &gate_addr) == 0) {
      net_del_gateway(gate_addr);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<net_clean_gateway>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    0xe7e(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    11c7 <net_clean_gateway+0x57>
lea    0xe56(%rip),%rdi
call   1090 <perror@plt>
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <net_clean_gateway+0xcb>
lea    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rdx
mov    $0x82,%esi
call   1050 <fgets@plt>
lea    -0x90(%rbp),%rdi
mov    -0x98(%rbp),%rdx
mov    $0x82,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1228 <net_clean_gateway+0xb8>
lea    -0x90(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <net_search_gateway@plt>
cmp    $0x0,%rax
jne    1223 <net_clean_gateway+0xb3>
mov    -0x8(%rbp),%edi
call   1070 <net_del_gateway@plt>
jmp    11df <net_clean_gateway+0x6f>
mov    -0x98(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_clean_gateway>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
lea    0xe7d(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1227 <net_clean_gateway+0xb7>
mov    %rax,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x82,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    $0x82,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1210 <net_clean_gateway+0xa0>
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r15
jmp    11f5 <net_clean_gateway+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x82,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1210 <net_clean_gateway+0xa0>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <net_search_gateway@plt>
test   %rax,%rax
jne    11e0 <net_clean_gateway+0x70>
mov    0xc(%rsp),%edi
call   1070 <net_del_gateway@plt>
jmp    11e0 <net_clean_gateway+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd2(%rip),%rdi
call   1090 <perror@plt>
lea    0xdd8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    121a <net_clean_gateway+0xaa>

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/net/route\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [44 x i8] c"INET (IPv4) not configured in this system.\0A\00"
define i32 @net_clean_gateway() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [132 x i8]
%4 = alloca i32*
%5 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 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 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
11: ; preds = %0
%12 = getelementptr inbounds [132 x i8], [132 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i32* @fgets(i8* %12, i32 130, i32* %13)
br label %15
15: ; preds = %27, %11
%16 = getelementptr inbounds [132 x i8], [132 x i8]* %3, i64 0, i64 0
%17 = load i32*, i32** %4
%18 = call i32* @fgets(i8* %16, i32 130, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = getelementptr inbounds [132 x i8], [132 x i8]* %3, i64 0, i64 0
%22 = call i64 @net_search_gateway(i8* %21, i32* %2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %2
%26 = call i32 @net_del_gateway(i32 %25)
br label %27
27: ; preds = %24, %20
br label %15
28: ; preds = %15
%29 = load i32*, i32** %4
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %1
br label %31
31: ; preds = %28, %8
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/net/route\00"
@.str.1 = [2 x i8] c"r\00"
@str = [43 x i8] c"INET (IPv4) not configured in this system.\00"
define i32 @net_clean_gateway() {
%1 = alloca i32
%2 = alloca [132 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [132 x i8], [132 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %25
10: ; preds = %0
%11 = call i32* @fgets(i8* %4, i32 130, i32* %5)
%12 = call i32* @fgets(i8* %4, i32 130, i32* %5)
%13 = icmp eq i32* %12, null
br i1 %13, label %23, label %14
14: ; preds = %10, %20
%15 = call i64 @net_search_gateway(i8* %4, i32* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %1
%19 = call i32 @net_del_gateway(i32 %18)
br label %20
20: ; preds = %17, %14
%21 = call i32* @fgets(i8* %4, i32 130, i32* %5)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %14
23: ; preds = %20, %10
%24 = call i32 @fclose(i32* %5)
br label %25
25: ; preds = %23, %7
%26 = phi i32 [ 0, %23 ], [ -1, %7 ]
ret i32 %26
}