#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*/ abms_net_dhcp(char *);
int /*<<< orphan*/ abms_net_linkup(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isspace(char);
char *strchr(char *, char);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void abms_net_dhcpscan(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, "lo", 2)) {
        abms_net_linkup(devname);
        abms_net_dhcp(devname);
      } else if ((!strncmp(devname, "lo", 2)) && (strlen(devname) > 3)) {
        abms_net_linkup(devname);
        abms_net_dhcp(devname);
      }
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<abms_net_dhcpscan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    0xe5e(%rip),%rdi
lea    0xe65(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
jne    11c4 <abms_net_dhcpscan+0x34>
jmp    1300 <abms_net_dhcpscan+0x170>
jmp    11c9 <abms_net_dhcpscan+0x39>
lea    -0x200(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x200,%esi
call   1090 <fgets@plt>
mov    %rax,-0x210(%rbp)
cmp    $0x0,%rax
je     12f4 <abms_net_dhcpscan+0x164>
jmp    11f7 <abms_net_dhcpscan+0x67>
mov    -0x210(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isspace@plt>
cmp    $0x0,%rax
je     1227 <abms_net_dhcpscan+0x97>
mov    -0x210(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x210(%rbp)
jmp    11f7 <abms_net_dhcpscan+0x67>
mov    -0x210(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
mov    %rax,-0x208(%rbp)
cmpq   $0x0,-0x208(%rbp)
je     12ef <abms_net_dhcpscan+0x15f>
mov    -0x208(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x210(%rbp),%rdi
lea    0xdab(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1296 <abms_net_dhcpscan+0x106>
mov    -0x210(%rbp),%rdi
call   1040 <abms_net_linkup@plt>
mov    -0x210(%rbp),%rdi
call   10a0 <abms_net_dhcp@plt>
jmp    12ea <abms_net_dhcpscan+0x15a>
mov    -0x210(%rbp),%rdi
lea    0xd6c(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12e5 <abms_net_dhcpscan+0x155>
mov    -0x210(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x3,%eax
jle    12e5 <abms_net_dhcpscan+0x155>
mov    -0x210(%rbp),%rdi
call   1040 <abms_net_linkup@plt>
mov    -0x210(%rbp),%rdi
call   10a0 <abms_net_dhcp@plt>
jmp    12ea <abms_net_dhcpscan+0x15a>
jmp    12ef <abms_net_dhcpscan+0x15f>
jmp    11c9 <abms_net_dhcpscan+0x39>
mov    -0x218(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abms_net_dhcpscan>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
lea    0xe5b(%rip),%rdi
lea    0xe62(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1278 <abms_net_dhcpscan+0xe8>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1270 <abms_net_dhcpscan+0xe0>
mov    %rsp,%r14
lea    0xe30(%rip),%r15
jmp    1207 <abms_net_dhcpscan+0x77>
mov    %rbx,%rdi
call   1040 <abms_net_linkup@plt>
mov    %rbx,%rdi
call   10a0 <abms_net_dhcp@plt>
mov    %r14,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1270 <abms_net_dhcpscan+0xe0>
mov    %rax,%rbx
movsbl (%rax),%edi
call   1080 <isspace@plt>
mov    %rax,%rcx
lea    0x1(%rbx),%rax
test   %rcx,%rcx
jne    1207 <abms_net_dhcpscan+0x77>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     11f2 <abms_net_dhcpscan+0x62>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11e2 <abms_net_dhcpscan+0x52>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11f2 <abms_net_dhcpscan+0x62>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x4,%eax
jge    11e2 <abms_net_dhcpscan+0x52>
jmp    11f2 <abms_net_dhcpscan+0x62>
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 = [3 x i8] c"lo\00"
define void @abms_net_dhcpscan() {
%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 %58
8: ; preds = %0
br label %9
9: ; preds = %54, %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 %55
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 %54
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 ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i8*, i8** %3
%36 = call i32 @abms_net_linkup(i8* %35)
%37 = load i8*, i8** %3
%38 = call i32 @abms_net_dhcp(i8* %37)
br label %53
39: ; preds = %29
%40 = load i8*, i8** %3
%41 = call i64 @strncmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%42 = icmp ne i64 %41, 0
br i1 %42, label %52, label %43
43: ; preds = %39
%44 = load i8*, i8** %3
%45 = call i32 @strlen(i8* %44)
%46 = icmp sgt i32 %45, 3
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i8*, i8** %3
%49 = call i32 @abms_net_linkup(i8* %48)
%50 = load i8*, i8** %3
%51 = call i32 @abms_net_dhcp(i8* %50)
br label %52
52: ; preds = %47, %43, %39
br label %53
53: ; preds = %52, %34
br label %54
54: ; preds = %53, %24
br label %9
55: ; preds = %9
%56 = load i32*, i32** %4
%57 = call i32 @fclose(i32* %56)
br label %58
58: ; preds = %55, %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 = [3 x i8] c"lo\00"
define void @abms_net_dhcpscan() {
%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 %36, 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 %34, 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, %31
%15 = phi i8* [ %13, %8 ], [ %32, %31 ]
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 %31, label %19
19: ; preds = %16
store i8 0, i8* %17
%20 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = call i32 @strlen(i8* %9)
%27 = icmp sgt i32 %26, 3
br i1 %27, label %28, label %31
28: ; preds = %25, %19
%29 = call i32 @abms_net_linkup(i8* %9)
%30 = call i32 @abms_net_dhcp(i8* %9)
br label %31
31: ; preds = %28, %25, %22, %16
%32 = call i8* @fgets(i8* %2, i32 512, i32* %3)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %14
34: ; preds = %31, %5
%35 = call i32 @fclose(i32* %3)
br label %36
36: ; preds = %0, %34
ret void
}