#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*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ kattach_net_dhcp(char *);
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
void kattach_net_vkaos(void) {
  char entry[512];
  char *delimit;
  char *devname;
  FILE *fp;
  if (!(fp = fopen("/proc/net/dev", "r")))
    return;
  while ((devname = fgets(entry, 512, fp))) {
    while (isspace(devname[0]))
      devname++;
    delimit = strchr(devname, ':');
    if (delimit) {
      *delimit = 0;
      if (strncmp(devname, "eth", 3)) {
        kattach_net_dhcp(devname);
      }
    }
  }
  fclose(fp);
  return;
}


x86 assembly (clang, -O0):
<kattach_net_vkaos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    0xe7e(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
jne    11a4 <kattach_net_vkaos+0x34>
jmp    127b <kattach_net_vkaos+0x10b>
jmp    11a9 <kattach_net_vkaos+0x39>
lea    -0x200(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x200,%esi
call   1080 <fgets@plt>
mov    %rax,-0x210(%rbp)
cmp    $0x0,%rax
je     126f <kattach_net_vkaos+0xff>
jmp    11d7 <kattach_net_vkaos+0x67>
mov    -0x210(%rbp),%rax
movsbl (%rax),%edi
call   1070 <isspace@plt>
cmp    $0x0,%rax
je     1207 <kattach_net_vkaos+0x97>
mov    -0x210(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x210(%rbp)
jmp    11d7 <kattach_net_vkaos+0x67>
mov    -0x210(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x208(%rbp)
cmpq   $0x0,-0x208(%rbp)
je     126a <kattach_net_vkaos+0xfa>
mov    -0x208(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x210(%rbp),%rdi
lea    0xdcb(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1265 <kattach_net_vkaos+0xf5>
mov    -0x210(%rbp),%rdi
call   1040 <kattach_net_dhcp@plt>
jmp    126a <kattach_net_vkaos+0xfa>
jmp    11a9 <kattach_net_vkaos+0x39>
mov    -0x218(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kattach_net_vkaos>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1228 <kattach_net_vkaos+0xb8>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1220 <kattach_net_vkaos+0xb0>
mov    %rsp,%r14
lea    0xe54(%rip),%r15
jmp    11d5 <kattach_net_vkaos+0x65>
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1220 <kattach_net_vkaos+0xb0>
mov    %rax,%rbx
movsbl (%rax),%edi
call   1070 <isspace@plt>
mov    %rax,%rcx
lea    0x1(%rbx),%rax
test   %rcx,%rcx
jne    11d5 <kattach_net_vkaos+0x65>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11c0 <kattach_net_vkaos+0x50>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c0 <kattach_net_vkaos+0x50>
mov    %rbx,%rdi
call   1040 <kattach_net_dhcp@plt>
jmp    11c0 <kattach_net_vkaos+0x50>
mov    %r12,%rdi
call   1050 <fclose@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"eth\00"
define void @kattach_net_vkaos() {
%1 = alloca [512 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 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 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
br label %42
8: ; preds = %0
br label %9
9: ; preds = %38, %8
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%11 = load i32*, i32** %4
%12 = call i8* @fgets(i8* %10, i32 512, i32* %11)
store i8* %12, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %39
14: ; preds = %9
br label %15
15: ; preds = %21, %14
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = call i64 @isspace(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
br label %15
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = call i8* @strchr(i8* %25, i8 signext 58)
store i8* %26, i8** %2
%27 = load i8*, i8** %2
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %38
29: ; preds = %24
%30 = load i8*, i8** %2
store i8 0, i8* %30
%31 = load i8*, i8** %3
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i8*, i8** %3
%36 = call i32 @kattach_net_dhcp(i8* %35)
br label %37
37: ; preds = %34, %29
br label %38
38: ; preds = %37, %24
br label %9
39: ; preds = %9
%40 = load i32*, i32** %4
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %39, %7
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/dev\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"eth\00"
define void @kattach_net_vkaos() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %29, label %5
5: ; preds = %0
%6 = call i8* @fgets(i8* %2, i32 512, i32* %3)
%7 = icmp eq i8* %6, null
br i1 %7, label %27, label %8
8: ; preds = %5, %14
%9 = phi i8* [ %15, %14 ], [ %6, %5 ]
%10 = load i8, i8* %9
%11 = call i64 @isspace(i8 signext %10)
%12 = icmp eq i64 %11, 0
%13 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %12, label %16, label %14
14: ; preds = %8, %24
%15 = phi i8* [ %13, %8 ], [ %25, %24 ]
br label %8
16: ; preds = %8
%17 = call i8* @strchr(i8* %9, i8 signext 58)
%18 = icmp eq i8* %17, null
br i1 %18, label %24, label %19
19: ; preds = %16
store i8 0, i8* %17
%20 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @kattach_net_dhcp(i8* %9)
br label %24
24: ; preds = %19, %22, %16
%25 = call i8* @fgets(i8* %2, i32 512, i32* %3)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %14
27: ; preds = %24, %5
%28 = call i32 @fclose(i32* %3)
br label %29
29: ; preds = %0, %27
ret void
}