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

/* Variables and functions */
int check_file(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ setDNS(char *);
int /*<<< orphan*/ setGateway(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strtok(char *, char *);
int /*<<< orphan*/ system(char *);
void handle_network_settings() {
  char line[100], dns[100], gw[100], route[100] = "ip route add default via ";
  FILE *net;
  if (check_file("/tmp/new_network") != -1) {
    net = fopen("/tmp/new_network", "r");
    if (net != NULL) {
      fgets(line, 100, net);
      strtok(line, " ");
      strcpy(gw, line);
      fgets(line, 100, net);
      strtok(line, "");
      strcpy(dns, line);
      setGateway(gw);
      setDNS(dns);
      system("ip route delete default");
      strcat(route, gw);
      system(route);
      fclose(net);
    }
    remove("/tmp/new_network");
  }
}


x86 assembly (clang, -O0):
<handle_network_settings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
lea    -0x1c0(%rbp),%rdi
lea    0xe27(%rip),%rsi
mov    $0x64,%edx
call   1090 <memcpy@plt>
lea    0xe7a(%rip),%rdi
call   10b0 <check_file@plt>
cmp    $0xffffffff,%eax
je     12e5 <handle_network_settings+0x125>
lea    0xe65(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x1c8(%rbp)
cmpq   $0x0,-0x1c8(%rbp)
je     12d9 <handle_network_settings+0x119>
lea    -0x70(%rbp),%rdi
mov    -0x1c8(%rbp),%rdx
mov    $0x64,%esi
call   1080 <fgets@plt>
lea    -0x70(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   10d0 <strtok@plt>
lea    -0x150(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x70(%rbp),%rdi
mov    -0x1c8(%rbp),%rdx
mov    $0x64,%esi
call   1080 <fgets@plt>
lea    -0x70(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   10d0 <strtok@plt>
lea    -0xe0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x150(%rbp),%rdi
call   1060 <setGateway@plt>
lea    -0xe0(%rbp),%rdi
call   10a0 <setDNS@plt>
lea    0xdd0(%rip),%rdi
call   1070 <system@plt>
lea    -0x1c0(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0x1c0(%rbp),%rdi
call   1070 <system@plt>
mov    -0x1c8(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd84(%rip),%rdi
call   1030 <remove@plt>
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_network_settings>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1b8,%rsp
movaps 0xe8b(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe6f(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe53(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe37(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe1b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xdff(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe50(%rip),%rdi
call   10a0 <check_file@plt>
cmp    $0xffffffff,%eax
je     12f0 <handle_network_settings+0x140>
lea    0xe3b(%rip),%rdi
lea    0xe45(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12e4 <handle_network_settings+0x134>
mov    %rax,%rbx
lea    0x150(%rsp),%r15
mov    %r15,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
lea    0xe17(%rip),%rsi
mov    %r15,%rdi
call   10c0 <strtok@plt>
lea    0x70(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    $0x64,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
lea    0xde9(%rip),%rsi
mov    %r15,%rdi
call   10c0 <strtok@plt>
lea    0xe0(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1060 <setGateway@plt>
mov    %r12,%rdi
call   1090 <setDNS@plt>
lea    0xdb8(%rip),%rdi
call   1070 <system@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   10d0 <strcat@plt>
mov    %r15,%rdi
call   1070 <system@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xd79(%rip),%rdi
call   1030 <remove@plt>
add    $0x1b8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.handle_network_settings.route = [100 x i8] c"ip route add default via \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [17 x i8] c"/tmp/new_network\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [24 x i8] c"ip route delete default\00"
define void @handle_network_settings() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca i32*
%6 = bitcast [100 x i8]* %4 to i8*
%7 = call i32 @check_file(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %44
9: ; preds = %0
%10 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %42
13: ; preds = %9
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%15 = load i32*, i32** %5
%16 = call i32 @fgets(i8* %14, i32 100, i32* %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%18 = call i32 @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%23 = load i32*, i32** %5
%24 = call i32 @fgets(i8* %22, i32 100, i32* %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%26 = call i32 @strtok(i8* %25, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%31 = call i32 @setGateway(i8* %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%33 = call i32 @setDNS(i8* %32)
%34 = call i32 @system(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%37 = call i32 @strcat(i8* %35, i8* %36)
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%39 = call i32 @system(i8* %38)
%40 = load i32*, i32** %5
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %13, %9
%43 = call i32 @remove(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %42, %0
ret void
}

LLVM IR (-O2):
@__const.handle_network_settings.route = [100 x i8] c"ip route add default via \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [17 x i8] c"/tmp/new_network\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [24 x i8] c"ip route delete default\00"
define void @handle_network_settings() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = tail call i32 @check_file(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, -1
br i1 %10, label %29, label %11
11: ; preds = %0
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %27, label %14
14: ; preds = %11
%15 = call i32 @fgets(i8* %5, i32 100, i32* %12)
%16 = call i32 @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @strcpy(i8* %7, i8* %5)
%18 = call i32 @fgets(i8* %5, i32 100, i32* %12)
%19 = call i32 @strtok(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @strcpy(i8* %6, i8* %5)
%21 = call i32 @setGateway(i8* %7)
%22 = call i32 @setDNS(i8* %6)
%23 = call i32 @system(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @strcat(i8* %8, i8* %7)
%25 = call i32 @system(i8* %8)
%26 = call i32 @fclose(i32* %12)
br label %27
27: ; preds = %14, %11
%28 = call i32 @remove(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %0
ret void
}