#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 hv_kvp_ipaddr_value {
  int dhcp_enabled;
  scalar_t__ dns_addr;
  scalar_t__ gate_way;
};
typedef int /*<<< orphan*/ dhcp_info;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ INET6_ADDRSTRLEN;
int /*<<< orphan*/ INET_ADDRSTRLEN;
int MAX_GATEWAY_SIZE;
int MAX_IP_ADDR_SIZE;
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ kvp_process_ipconfig_file(char *, char *, int,
                                             int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
void kvp_get_ipconfig_info(char *if_name, struct hv_kvp_ipaddr_value *buffer) {
  char cmd[512];
  char dhcp_info[128];
  char *p;
  FILE *file;
  sprintf(cmd, "%s %s", "ip route show dev", if_name);
  strcat(cmd, " | awk '/default/ {print $3 }'");
  kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way,
                            (MAX_GATEWAY_SIZE * 2), INET_ADDRSTRLEN, 0);
  sprintf(cmd, "%s %s", "ip -f inet6  route show dev", if_name);
  strcat(cmd, " | awk '/default/ {print $3 }'");
  kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way,
                            (MAX_GATEWAY_SIZE * 2), INET6_ADDRSTRLEN, 1);
  sprintf(cmd, "%s", "hv_get_dns_info");
  kvp_process_ipconfig_file(cmd, (char *)buffer->dns_addr,
                            (MAX_IP_ADDR_SIZE * 2), INET_ADDRSTRLEN, 0);
  sprintf(cmd, "%s %s", "hv_get_dhcp_info", if_name);
  file = popen(cmd, "r");
  if (file == NULL)
    return;
  p = fgets(dhcp_info, sizeof(dhcp_info), file);
  if (p == NULL) {
    pclose(file);
    return;
  }
  if (!strncmp(p, "Enabled", 7))
    buffer->dhcp_enabled = 1;
  else
    buffer->dhcp_enabled = 0;
  pclose(file);
}


x86 assembly (clang, -O0):
<kvp_get_ipconfig_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    0xe6b(%rip),%rsi
lea    0xe6a(%rip),%rdx
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x210(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
shl    $0x1,%edx
mov    0x2df8(%rip),%rax
mov    (%rax),%ecx
xor    %r8d,%r8d
call   1040 <kvp_process_ipconfig_file@plt>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    0xe0c(%rip),%rsi
lea    0xe3c(%rip),%rdx
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x210(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    0x2dad(%rip),%rax
mov    (%rax),%edx
shl    $0x1,%edx
mov    0x2db1(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%r8d
call   1040 <kvp_process_ipconfig_file@plt>
lea    -0x210(%rbp),%rdi
lea    0xdb1(%rip),%rsi
lea    0xdfa(%rip),%rdx
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
shl    $0x1,%edx
mov    0x2d4e(%rip),%rax
mov    (%rax),%ecx
xor    %r8d,%r8d
call   1040 <kvp_process_ipconfig_file@plt>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    0xd62(%rip),%rsi
lea    0xdbe(%rip),%rdx
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x210(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x2a0(%rbp)
cmpq   $0x0,-0x2a0(%rbp)
jne    12d9 <kvp_get_ipconfig_info+0x169>
jmp    135d <kvp_get_ipconfig_info+0x1ed>
lea    -0x290(%rbp),%rdi
mov    -0x2a0(%rbp),%rdx
mov    $0x80,%esi
call   1060 <fgets@plt>
mov    %rax,-0x298(%rbp)
cmpq   $0x0,-0x298(%rbp)
jne    1317 <kvp_get_ipconfig_info+0x1a7>
mov    -0x2a0(%rbp),%rdi
call   1050 <pclose@plt>
jmp    135d <kvp_get_ipconfig_info+0x1ed>
mov    -0x298(%rbp),%rdi
lea    0xd51(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1347 <kvp_get_ipconfig_info+0x1d7>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    1351 <kvp_get_ipconfig_info+0x1e1>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x2a0(%rbp),%rdi
call   1050 <pclose@plt>
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvp_get_ipconfig_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x288,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe72(%rip),%rbp
lea    0xe71(%rip),%rdx
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rcx
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xe64(%rip),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
mov    0x10(%r14),%rsi
mov    0x2e0e(%rip),%r12
mov    (%r12),%edx
add    %edx,%edx
mov    0x2df9(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
xor    %r8d,%r8d
call   1040 <kvp_process_ipconfig_file@plt>
lea    0xe4c(%rip),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rcx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
mov    0x10(%r14),%rsi
mov    (%r12),%edx
add    %edx,%edx
mov    0x2dd1(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    $0x1,%r8d
call   1040 <kvp_process_ipconfig_file@plt>
movups 0xe25(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
mov    0x8(%r14),%rsi
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
add    %edx,%edx
mov    0x2d84(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
xor    %r8d,%r8d
call   1040 <kvp_process_ipconfig_file@plt>
lea    0xe03(%rip),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rcx
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xdfd(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     12c2 <kvp_get_ipconfig_info+0x152>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12ba <kvp_get_ipconfig_info+0x14a>
lea    0xdd3(%rip),%rsi
mov    %rax,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,(%r14)
mov    %rbx,%rdi
call   1050 <pclose@plt>
add    $0x288,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hv_kvp_ipaddr_value = type { i32, i64, i64 }
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [18 x i8] c"ip route show dev\00"
@.str.2 = [31 x i8] c" | awk '/default/ {print $3 }'\00"
@MAX_GATEWAY_SIZE = global i32 0
@INET_ADDRSTRLEN = global i32 0
@.str.3 = [28 x i8] c"ip -f inet6 route show dev\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [16 x i8] c"hv_get_dns_info\00"
@MAX_IP_ADDR_SIZE = global i32 0
@.str.6 = [17 x i8] c"hv_get_dhcp_info\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [8 x i8] c"Enabled\00"
define void @kvp_get_ipconfig_info(i8* %0, %struct.hv_kvp_ipaddr_value* %1) {
%3 = alloca i8*
%4 = alloca %struct.hv_kvp_ipaddr_value*
%5 = alloca [512 x i8]
%6 = alloca [128 x i8]
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %3
store %struct.hv_kvp_ipaddr_value* %1, %struct.hv_kvp_ipaddr_value** %4
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%15 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %4
%16 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %15, i32 0, i32 2
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to i8*
%19 = load i32, i32* @MAX_GATEWAY_SIZE
%20 = mul nsw i32 %19, 2
%21 = load i32, i32* @INET_ADDRSTRLEN
%22 = call i32 @kvp_process_ipconfig_file(i8* %14, i8* %18, i32 %20, i32 %21, i32 0)
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%24 = load i8*, i8** %3
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%29 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %4
%30 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %29, i32 0, i32 2
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to i8*
%33 = load i32, i32* @MAX_GATEWAY_SIZE
%34 = mul nsw i32 %33, 2
%35 = load i32, i32* @INET6_ADDRSTRLEN
%36 = call i32 @kvp_process_ipconfig_file(i8* %28, i8* %32, i32 %34, i32 %35, i32 1)
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%38 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%40 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %4
%41 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %40, i32 0, i32 1
%42 = load i64, i64* %41
%43 = inttoptr i64 %42 to i8*
%44 = load i32, i32* @MAX_IP_ADDR_SIZE
%45 = mul nsw i32 %44, 2
%46 = load i32, i32* @INET_ADDRSTRLEN
%47 = call i32 @kvp_process_ipconfig_file(i8* %39, i8* %43, i32 %45, i32 %46, i32 0)
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%49 = load i8*, i8** %3
%50 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %49)
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%52 = call i32* @popen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %52, i32** %8
%53 = load i32*, i32** %8
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %56
55: ; preds = %2
br label %78
56: ; preds = %2
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%58 = load i32*, i32** %8
%59 = call i8* @fgets(i8* %57, i32 128, i32* %58)
store i8* %59, i8** %7
%60 = load i8*, i8** %7
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %56
%63 = load i32*, i32** %8
%64 = call i32 @pclose(i32* %63)
br label %78
65: ; preds = %56
%66 = load i8*, i8** %7
%67 = call i32 @strncmp(i8* %66, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 7)
%68 = icmp ne i32 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %65
%70 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %4
%71 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %70, i32 0, i32 0
store i32 1, i32* %71
br label %75
72: ; preds = %65
%73 = load %struct.hv_kvp_ipaddr_value*, %struct.hv_kvp_ipaddr_value** %4
%74 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %73, i32 0, i32 0
store i32 0, i32* %74
br label %75
75: ; preds = %72, %69
%76 = load i32*, i32** %8
%77 = call i32 @pclose(i32* %76)
br label %78
78: ; preds = %75, %62, %55
ret void
}

LLVM IR (-O2):
%struct.hv_kvp_ipaddr_value = type { i32, i64, i64 }
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [18 x i8] c"ip route show dev\00"
@.str.2 = [31 x i8] c" | awk '/default/ {print $3 }'\00"
@MAX_GATEWAY_SIZE = global i32 0
@INET_ADDRSTRLEN = global i32 0
@.str.3 = [28 x i8] c"ip -f inet6 route show dev\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.5 = [16 x i8] c"hv_get_dns_info\00"
@MAX_IP_ADDR_SIZE = global i32 0
@.str.6 = [17 x i8] c"hv_get_dhcp_info\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [8 x i8] c"Enabled\00"
define void @kvp_get_ipconfig_info(i8* %0, %struct.hv_kvp_ipaddr_value* nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%9 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %1, i64 0, i32 2
%10 = load i64, i64* %9
%11 = inttoptr i64 %10 to i8*
%12 = load i32, i32* @MAX_GATEWAY_SIZE
%13 = shl nsw i32 %12, 1
%14 = load i32, i32* @INET_ADDRSTRLEN
%15 = call i32 @kvp_process_ipconfig_file(i8* %5, i8* %11, i32 %13, i32 %14, i32 0)
%16 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%17 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%18 = load i64, i64* %9
%19 = inttoptr i64 %18 to i8*
%20 = load i32, i32* @MAX_GATEWAY_SIZE
%21 = shl nsw i32 %20, 1
%22 = load i32, i32* @INET6_ADDRSTRLEN
%23 = call i32 @kvp_process_ipconfig_file(i8* %5, i8* %19, i32 %21, i32 %22, i32 1)
%24 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %1, i64 0, i32 1
%25 = load i64, i64* %24
%26 = inttoptr i64 %25 to i8*
%27 = load i32, i32* @MAX_IP_ADDR_SIZE
%28 = shl nsw i32 %27, 1
%29 = load i32, i32* @INET_ADDRSTRLEN
%30 = call i32 @kvp_process_ipconfig_file(i8* %5, i8* %26, i32 %28, i32 %29, i32 0)
%31 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%32 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %44, label %34
34: ; preds = %2
%35 = call i8* @fgets(i8* %6, i32 128, i32* %32)
%36 = icmp eq i8* %35, null
br i1 %36, label %42, label %37
37: ; preds = %34
%38 = call i32 @strncmp(i8* %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 7)
%39 = icmp eq i32 %38, 0
%40 = zext i1 %39 to i32
%41 = getelementptr inbounds %struct.hv_kvp_ipaddr_value, %struct.hv_kvp_ipaddr_value* %1, i64 0, i32 0
store i32 %40, i32* %41
br label %42
42: ; preds = %34, %37
%43 = call i32 @pclose(i32* %32)
br label %44
44: ; preds = %42, %2
ret void
}