#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int strlen(char *);
void kvp_process_ipconfig_file(char *cmd, char *config_buf, int len,
                               int element_size, int offset) {
  char buf[256];
  char *p;
  char *x;
  FILE *file;
  file = popen(cmd, "r");
  if (file == NULL)
    return;
  if (offset == 0)
    memset(config_buf, 0, len);
  while ((p = fgets(buf, sizeof(buf), file)) != NULL) {
    if ((len - strlen(config_buf)) < (element_size + 1))
      break;
    x = strchr(p, '\n');
    *x = '\0';
    strcat(config_buf, p);
    strcat(config_buf, ";");
  }
  pclose(file);
}


x86 assembly (clang, -O0):
<kvp_process_ipconfig_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    11b7 <kvp_process_ipconfig_file+0x47>
jmp    127f <kvp_process_ipconfig_file+0x10f>
cmpl   $0x0,-0x1c(%rbp)
jne    11cf <kvp_process_ipconfig_file+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
jmp    11d4 <kvp_process_ipconfig_file+0x64>
lea    -0x120(%rbp),%rdi
mov    -0x138(%rbp),%rdx
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
je     1273 <kvp_process_ipconfig_file+0x103>
mov    -0x14(%rbp),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x13c(%rbp),%eax
sub    %ecx,%eax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    122c <kvp_process_ipconfig_file+0xbc>
jmp    1273 <kvp_process_ipconfig_file+0x103>
mov    -0x128(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1090 <strcat@plt>
jmp    11d4 <kvp_process_ipconfig_file+0x64>
mov    -0x138(%rbp),%rdi
call   1050 <pclose@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvp_process_ipconfig_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%rbx
lea    0xe6c(%rip),%rsi
call   1080 <popen@plt>
test   %rax,%rax
je     123c <kvp_process_ipconfig_file+0xcc>
mov    %rax,%rbp
test   %r12d,%r12d
jne    11b7 <kvp_process_ipconfig_file+0x47>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rbp,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1234 <kvp_process_ipconfig_file+0xc4>
mov    %rax,%r12
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15d,%ecx
sub    %eax,%ecx
cmp    %r14d,%ecx
jle    1234 <kvp_process_ipconfig_file+0xc4>
mov    %r12,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
lea    0xdeb(%rip),%rsi
call   1090 <strcat@plt>
mov    %r13,%rdi
mov    $0x100,%esi
mov    %rbp,%rdx
call   1070 <fgets@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11e0 <kvp_process_ipconfig_file+0x70>
mov    %rbp,%rdi
call   1050 <pclose@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c";\00"
define void @kvp_process_ipconfig_file(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%15 = load i8*, i8** %6
%16 = call i32* @popen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %14
%17 = load i32*, i32** %14
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %5
br label %54
20: ; preds = %5
%21 = load i32, i32* %10
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8*, i8** %7
%25 = load i32, i32* %8
%26 = call i32 @memset(i8* %24, i32 0, i32 %25)
br label %27
27: ; preds = %23, %20
br label %28
28: ; preds = %42, %27
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%30 = load i32*, i32** %14
%31 = call i8* @fgets(i8* %29, i32 256, i32* %30)
store i8* %31, i8** %12
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %51
33: ; preds = %28
%34 = load i32, i32* %8
%35 = load i8*, i8** %7
%36 = call i32 @strlen(i8* %35)
%37 = sub nsw i32 %34, %36
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
%40 = icmp slt i32 %37, %39
br i1 %40, label %41, label %42
41: ; preds = %33
br label %51
42: ; preds = %33
%43 = load i8*, i8** %12
%44 = call i8* @strchr(i8* %43, i8 signext 10)
store i8* %44, i8** %13
%45 = load i8*, i8** %13
store i8 0, i8* %45
%46 = load i8*, i8** %7
%47 = load i8*, i8** %12
%48 = call i32 @strcat(i8* %46, i8* %47)
%49 = load i8*, i8** %7
%50 = call i32 @strcat(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %28
51: ; preds = %41, %28
%52 = load i32*, i32** %14
%53 = call i32 @pclose(i32* %52)
br label %54
54: ; preds = %51, %19
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c";\00"
define void @kvp_process_ipconfig_file(i8* nocapture %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %30, label %10
10: ; preds = %5
%11 = icmp eq i32 %4, 0
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @memset(i8* %1, i32 0, i32 %2)
br label %14
14: ; preds = %12, %10
%15 = call i8* @fgets(i8* %7, i32 256, i32* %8)
%16 = icmp eq i8* %15, null
br i1 %16, label %28, label %17
17: ; preds = %14, %22
%18 = phi i8* [ %26, %22 ], [ %15, %14 ]
%19 = call i32 @strlen(i8* %1)
%20 = sub nsw i32 %2, %19
%21 = icmp sgt i32 %20, %3
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = call i8* @strchr(i8* %18, i8 signext 10)
store i8 0, i8* %23
%24 = call i32 @strcat(i8* %1, i8* %18)
%25 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = call i8* @fgets(i8* %7, i32 256, i32* %8)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %17
28: ; preds = %22, %17, %14
%29 = call i32 @pclose(i32* %8)
br label %30
30: ; preds = %5, %28
ret void
}