#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 */
struct in_addr {
  int s_addr;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ IFNAMSIZ;
char *calloc(scalar_t__, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memcpy(char *, char *, scalar_t__);
scalar_t__ strcmp(char *, char *);
char *strtok_r(char *, char *, char **);
int strtol(char *, char **, int);
int utGetDefaultGwInfo(char **szDevPtr, char **szIpPtr) {
  FILE *f;
  char line[100];
  char *p, *c, *g;
  char *saveptr;
  int ret = 1;
  f = fopen("/proc/net/route", "r");
  while (fgets(line, 100, f)) {
    p = strtok_r(line, " \t", &saveptr);
    c = strtok_r(NULL, " \t", &saveptr);
    g = strtok_r(NULL, " \t", &saveptr);
    if (p && c) {
      if (strcmp(c, "00000000") == 0) {
        *szDevPtr = calloc(IFNAMSIZ, sizeof(char));
        memcpy(*szDevPtr, p, IFNAMSIZ - 1);
        *szIpPtr = NULL;
        if (g) {
          char *pEnd;
          int ng = strtol(g, &pEnd, 16);
          struct in_addr addr;
          addr.s_addr = ng;
          *szIpPtr = calloc(IFNAMSIZ, sizeof(char));
          memcpy(*szIpPtr, inet_ntoa(addr), IFNAMSIZ - 1);
          ret = 0;
        }
        break;
      }
    }
  }
  fclose(f);
  return ret;
}


x86 assembly (clang, -O0):
<utGetDefaultGwInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0xa4(%rbp)
lea    0xe4c(%rip),%rdi
lea    0xe55(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1362 <utGetDefaultGwInfo+0x1d2>
lea    -0x80(%rbp),%rdi
lea    0xe27(%rip),%rsi
lea    -0xa0(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x88(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe09(%rip),%rsi
lea    -0xa0(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x90(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdeb(%rip),%rsi
lea    -0xa0(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     135d <utGetDefaultGwInfo+0x1cd>
cmpq   $0x0,-0x90(%rbp)
je     135d <utGetDefaultGwInfo+0x1cd>
mov    -0x90(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1358 <utGetDefaultGwInfo+0x1c8>
mov    0x2d66(%rip),%rax
mov    (%rax),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x88(%rbp),%rsi
mov    0x2d3a(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   10a0 <memcpy@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x98(%rbp)
je     1353 <utGetDefaultGwInfo+0x1c3>
mov    -0x98(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    $0x10,%edx
call   1090 <strtol@plt>
mov    %eax,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
mov    %eax,-0xb8(%rbp)
mov    0x2ce4(%rip),%rax
mov    (%rax),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xc0(%rbp)
mov    -0xb8(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    -0xc0(%rbp),%rdi
mov    %rax,%rsi
mov    0x2ca3(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   10a0 <memcpy@plt>
movl   $0x0,-0xa4(%rbp)
jmp    1362 <utGetDefaultGwInfo+0x1d2>
jmp    135d <utGetDefaultGwInfo+0x1cd>
jmp    11c4 <utGetDefaultGwInfo+0x34>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xa4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utGetDefaultGwInfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe52(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   10b0 <fopen@plt>
lea    0x30(%rsp),%rdi
mov    $0x64,%esi
mov    %rax,0x8(%rsp)
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     12f9 <utGetDefaultGwInfo+0x169>
mov    %rbx,0x10(%rsp)
mov    %r14,0x18(%rsp)
lea    0xe22(%rip),%rbp
lea    0x30(%rsp),%rbx
lea    0x28(%rsp),%r14
jmp    121b <utGetDefaultGwInfo+0x8b>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    0x8(%rsp),%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12f4 <utGetDefaultGwInfo+0x164>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%r12
xor    %edi,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%r13
xor    %edi,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <strtok_r@plt>
test   %r12,%r12
je     1200 <utGetDefaultGwInfo+0x70>
test   %r13,%r13
je     1200 <utGetDefaultGwInfo+0x70>
mov    %rax,%r15
mov    %r13,%rdi
lea    0xdb5(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1200 <utGetDefaultGwInfo+0x70>
mov    0x2d6f(%rip),%r14
mov    (%r14),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
mov    (%r14),%rdx
add    $0xffffffffffffffff,%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   10a0 <memcpy@plt>
mov    0x18(%rsp),%rbx
movq   $0x0,(%rbx)
test   %r15,%r15
je     12f9 <utGetDefaultGwInfo+0x169>
lea    0x20(%rsp),%rsi
mov    %r15,%rdi
mov    $0x10,%edx
call   1090 <strtol@plt>
mov    %eax,%r15d
mov    (%r14),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbp
mov    %rax,(%rbx)
mov    %r15d,%edi
call   1030 <inet_ntoa@plt>
mov    (%r14),%rdx
add    $0xffffffffffffffff,%rdx
mov    %rbp,%rdi
mov    %rax,%rsi
call   10a0 <memcpy@plt>
xor    %ebp,%ebp
jmp    12f9 <utGetDefaultGwInfo+0x169>
mov    $0x1,%ebp
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.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"
@IFNAMSIZ = global i64 0
define i32 @utGetDefaultGwInfo(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca [100 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca %struct.in_addr
store i8** %0, i8*** %3
store i8** %1, i8*** %4
store i32 1, i32* %11
%15 = 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* %15, i32** %5
br label %16
16: ; preds = %66, %2
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = call i64 @fgets(i8* %17, i32 100, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %67
21: ; preds = %16
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%23 = call i8* @strtok_r(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %10)
store i8* %23, i8** %7
%24 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %10)
store i8* %24, i8** %8
%25 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %10)
store i8* %25, i8** %9
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %66
28: ; preds = %21
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %66
31: ; preds = %28
%32 = load i8*, i8** %8
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %65
35: ; preds = %31
%36 = load i64, i64* @IFNAMSIZ
%37 = call i8* @calloc(i64 %36, i32 1)
%38 = load i8**, i8*** %3
store i8* %37, i8** %38
%39 = load i8**, i8*** %3
%40 = load i8*, i8** %39
%41 = load i8*, i8** %7
%42 = load i64, i64* @IFNAMSIZ
%43 = sub nsw i64 %42, 1
%44 = call i32 @memcpy(i8* %40, i8* %41, i64 %43)
%45 = load i8**, i8*** %4
store i8* null, i8** %45
%46 = load i8*, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %64
48: ; preds = %35
%49 = load i8*, i8** %9
%50 = call i32 @strtol(i8* %49, i8** %12, i32 16)
store i32 %50, i32* %13
%51 = load i32, i32* %13
%52 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %14, i32 0, i32 0
store i32 %51, i32* %52
%53 = load i64, i64* @IFNAMSIZ
%54 = call i8* @calloc(i64 %53, i32 1)
%55 = load i8**, i8*** %4
store i8* %54, i8** %55
%56 = load i8**, i8*** %4
%57 = load i8*, i8** %56
%58 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %14, i32 0, i32 0
%59 = load i32, i32* %58
%60 = call i8* @inet_ntoa(i32 %59)
%61 = load i64, i64* @IFNAMSIZ
%62 = sub nsw i64 %61, 1
%63 = call i32 @memcpy(i8* %57, i8* %60, i64 %62)
store i32 0, i32* %11
br label %64
64: ; preds = %48, %35
br label %67
65: ; preds = %31
br label %66
66: ; preds = %65, %28, %21
br label %16
67: ; preds = %64, %16
%68 = load i32*, i32** %5
%69 = call i32 @fclose(i32* %68)
%70 = load i32, i32* %11
ret i32 %70
}

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"
@IFNAMSIZ = global i64 0
define i32 @utGetDefaultGwInfo(i8** nocapture writeonly %0, i8** nocapture writeonly %1) {
%3 = alloca [100 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = bitcast i8** %4 to i8*
%8 = 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))
%9 = call i64 @fgets(i8* %6, i32 100, i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %40, label %11
11: ; preds = %2, %37
%12 = call i8* @strtok_r(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %4)
%13 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %4)
%14 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %4)
%15 = icmp ne i8* %12, null
%16 = icmp ne i8* %13, null
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %37
18: ; preds = %11
%19 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %18
%22 = load i64, i64* @IFNAMSIZ
%23 = call i8* @calloc(i64 %22, i32 1)
store i8* %23, i8** %0
%24 = load i64, i64* @IFNAMSIZ
%25 = add nsw i64 %24, -1
%26 = call i32 @memcpy(i8* %23, i8* %12, i64 %25)
store i8* null, i8** %1
%27 = icmp eq i8* %14, null
br i1 %27, label %40, label %28
28: ; preds = %21
%29 = bitcast i8** %5 to i8*
%30 = call i32 @strtol(i8* %14, i8** %5, i32 16)
%31 = load i64, i64* @IFNAMSIZ
%32 = call i8* @calloc(i64 %31, i32 1)
store i8* %32, i8** %1
%33 = call i8* @inet_ntoa(i32 %30)
%34 = load i64, i64* @IFNAMSIZ
%35 = add nsw i64 %34, -1
%36 = call i32 @memcpy(i8* %32, i8* %33, i64 %35)
br label %40
37: ; preds = %18, %11
%38 = call i64 @fgets(i8* %6, i32 100, i32* %8)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %11
40: ; preds = %37, %2, %21, %28
%41 = phi i32 [ 0, %28 ], [ 1, %21 ], [ 1, %2 ], [ 1, %37 ]
%42 = call i32 @fclose(i32* %8)
ret i32 %41
}