#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
void getInterface(char *def_interface, int size) {
  FILE *fp;
  char line[256], *interface, *address;
  fp = fopen("/proc/net/route", "r");
  while (fgets(line, 256, fp)) {
    interface = strtok(line, " \t");
    address = strtok(NULL, " \t");
    if (interface && address && !strcmp(address, "00000000")) {
      strncpy(def_interface, interface, size - 1);
      break;
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<getInterface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1231 <getInterface+0xd1>
lea    -0x120(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x128(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe45(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     122c <getInterface+0xcc>
cmpq   $0x0,-0x130(%rbp)
je     122c <getInterface+0xcc>
mov    -0x130(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    122c <getInterface+0xcc>
mov    -0x8(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
jmp    1231 <getInterface+0xd1>
jmp    1189 <getInterface+0x29>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getInterface>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %esi,%r15d
mov    %rdi,0x8(%rsp)
lea    0xe80(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     121a <getInterface+0xba>
lea    0xe65(%rip),%rbp
lea    0x10(%rsp),%rbx
lea    0xe5c(%rip),%r13
jmp    11d5 <getInterface+0x75>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     121a <getInterface+0xba>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strtok@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %rbp,%rsi
call   1080 <strtok@plt>
test   %r14,%r14
je     11c0 <getInterface+0x60>
test   %rax,%rax
je     11c0 <getInterface+0x60>
mov    %rax,%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11c0 <getInterface+0x60>
add    $0xffffffff,%r15d
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/net/route\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c" \09\00"
@.str.3 = [9 x i8] c"00000000\00"
define void @getInterface(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = 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* %9, i32** %5
br label %10
10: ; preds = %34, %2
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = load i32*, i32** %5
%13 = call i64 @fgets(i8* %11, i32 256, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %35
15: ; preds = %10
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %17, i8** %7
%18 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %8
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %34
21: ; preds = %15
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i8*, i8** %8
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %24
%29 = load i8*, i8** %3
%30 = load i8*, i8** %7
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 1
%33 = call i32 @strncpy(i8* %29, i8* %30, i32 %32)
br label %35
34: ; preds = %24, %21, %15
br label %10
35: ; preds = %28, %10
%36 = load i32*, i32** %5
%37 = call i32 @fclose(i32* %36)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/net/route\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c" \09\00"
@.str.3 = [9 x i8] c"00000000\00"
define void @getInterface(i8* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, 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 = call i64 @fgets(i8* %4, i32 256, i32* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %2, %20
%9 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp ne i8* %9, null
%12 = icmp ne i8* %10, null
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = call i32 @strcmp(i8* %10, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = add nsw i32 %1, -1
%19 = call i32 @strncpy(i8* %0, i8* %9, i32 %18)
br label %23
20: ; preds = %14, %8
%21 = call i64 @fgets(i8* %4, i32 256, i32* %5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %8
23: ; preds = %20, %2, %17
%24 = call i32 @fclose(i32* %5)
ret void
}