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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ getpid();
int /*<<< orphan*/ osBZero(unsigned char *, unsigned long);
int /*<<< orphan*/ osSystem(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ utilIpStr2Ip(char *, unsigned char *);
int /*<<< orphan*/ utilStrTrim(char *);
long osDnsSvrGet(unsigned long lRecCnt, unsigned char *byIp) {
  char sCmd[128];
  char sTmpFn[32];
  FILE *pFile;
  char sLineBuf[128];
  long lCnt;
  if (byIp == 0)
    lRecCnt = 0;
  sprintf(sTmpFn, "/tmp/%ld.tmp", (long)getpid());
  sprintf(
      sCmd,
      "cat /tmp/resolv.conf.auto | grep -v -e '^search ' -e ' 127.0.0.1$' > %s",
      sTmpFn);
  if (osSystem(sCmd) != (0))
    return (-1);
  if ((pFile = fopen(sTmpFn, "r")) == (0))
    return (-1);
  osBZero(byIp, lRecCnt * 4);
  lCnt = 0;
  while (fgets(sLineBuf, sizeof(sLineBuf), pFile) != (0)) {
    utilStrTrim(sLineBuf);
    if (strlen(sLineBuf) == 0)
      continue;
    if (strncmp(sLineBuf, "nameserver ", 11) != 0)
      continue;
    if (lCnt < lRecCnt) {
      utilIpStr2Ip(sLineBuf + 11, &byIp[lCnt * 4]);
    }
    lCnt++;
  }
  fclose(pFile);
  unlink(sTmpFn);
  return lCnt;
}


x86 assembly (clang, -O0):
<osDnsSvrGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e6 <osDnsSvrGet+0x26>
movq   $0x0,-0x10(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x160(%rbp),%rdi
mov    %rax,%rdx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xc0(%rbp),%rdx
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
call   10a0 <osSystem@plt>
cmp    $0x0,%eax
je     1251 <osDnsSvrGet+0x91>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    137a <osDnsSvrGet+0x1ba>
lea    -0xc0(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0xc8(%rbp)
cmp    $0x0,%rax
jne    1282 <osDnsSvrGet+0xc2>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    137a <osDnsSvrGet+0x1ba>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
shl    $0x2,%rsi
call   10e0 <osBZero@plt>
movq   $0x0,-0x158(%rbp)
lea    -0x150(%rbp),%rdi
mov    -0xc8(%rbp),%rdx
mov    $0x80,%esi
call   1090 <fgets@plt>
cmp    $0x0,%eax
je     1357 <osDnsSvrGet+0x197>
lea    -0x150(%rbp),%rdi
call   10b0 <utilStrTrim@plt>
lea    -0x150(%rbp),%rdi
call   1080 <strlen@plt>
cmp    $0x0,%rax
jne    12e6 <osDnsSvrGet+0x126>
jmp    129e <osDnsSvrGet+0xde>
lea    -0x150(%rbp),%rdi
lea    0xd63(%rip),%rsi
mov    $0xb,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     130d <osDnsSvrGet+0x14d>
jmp    129e <osDnsSvrGet+0xde>
mov    -0x158(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1340 <osDnsSvrGet+0x180>
lea    -0x150(%rbp),%rdi
add    $0xb,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x158(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <utilIpStr2Ip@plt>
mov    -0x158(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x158(%rbp)
jmp    129e <osDnsSvrGet+0xde>
mov    -0xc8(%rbp),%rdi
call   1070 <fclose@plt>
lea    -0xc0(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x158(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<osDnsSvrGet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
test   %rsi,%rsi
cmove  %rsi,%r15
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xe24(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
lea    0xe1a(%rip),%rsi
lea    0xa0(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
call   1090 <osSystem@plt>
mov    $0xffffffffffffffff,%r12
test   %eax,%eax
jne    12dd <osDnsSvrGet+0x12d>
lea    0xe2f(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12dd <osDnsSvrGet+0x12d>
mov    %rax,%rbx
lea    0x0(,%r15,4),%rsi
mov    %r14,%rdi
call   10d0 <osBZero@plt>
lea    0x20(%rsp),%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
xor    %r12d,%r12d
test   %eax,%eax
je     12cd <osDnsSvrGet+0x11d>
lea    0x20(%rsp),%rbp
lea    0xde8(%rip),%r13
jmp    1294 <osDnsSvrGet+0xe4>
add    $0x1,%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %eax,%eax
je     12cd <osDnsSvrGet+0x11d>
mov    %rbp,%rdi
call   10a0 <utilStrTrim@plt>
cmpb   $0x0,0x20(%rsp)
je     1280 <osDnsSvrGet+0xd0>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0xb,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1280 <osDnsSvrGet+0xd0>
cmp    %r15,%r12
jae    1271 <osDnsSvrGet+0xc1>
lea    (%r14,%r12,4),%rsi
lea    0x2b(%rsp),%rdi
call   1030 <utilIpStr2Ip@plt>
jmp    1271 <osDnsSvrGet+0xc1>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %rsp,%rdi
call   1040 <unlink@plt>
mov    %r12,%rax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/%ld.tmp\00"
@.str.1 = [72 x i8] c"cat /tmp/resolv.conf.auto | grep -v -e '^search ' -e ' 127.0.0.1$' > %s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [12 x i8] c"nameserver \00"
define i64 @osDnsSvrGet(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca [128 x i8]
%7 = alloca [32 x i8]
%8 = alloca i32*
%9 = alloca [128 x i8]
%10 = alloca i64
store i64 %0, i64* %4
store i8* %1, i8** %5
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i64 0, i64* %4
br label %14
14: ; preds = %13, %2
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%16 = call i64 (...) @getpid()
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %16)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%22 = call i32 @osSystem(i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %14
store i64 -1, i64* %3
br label %73
25: ; preds = %14
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %8
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %25
store i64 -1, i64* %3
br label %73
30: ; preds = %25
%31 = load i8*, i8** %5
%32 = load i64, i64* %4
%33 = mul i64 %32, 4
%34 = call i32 @osBZero(i8* %31, i64 %33)
store i64 0, i64* %10
br label %35
35: ; preds = %64, %51, %46, %30
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%37 = load i32*, i32** %8
%38 = call i32 @fgets(i8* %36, i32 128, i32* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %67
40: ; preds = %35
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%42 = call i32 @utilStrTrim(i8* %41)
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%44 = call i64 @strlen(i8* %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %40
br label %35
47: ; preds = %40
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%49 = call i64 @strncmp(i8* %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 11)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %47
br label %35
52: ; preds = %47
%53 = load i64, i64* %10
%54 = load i64, i64* %4
%55 = icmp ult i64 %53, %54
br i1 %55, label %56, label %64
56: ; preds = %52
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%58 = getelementptr inbounds i8, i8* %57, i64 11
%59 = load i8*, i8** %5
%60 = load i64, i64* %10
%61 = mul nsw i64 %60, 4
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = call i32 @utilIpStr2Ip(i8* %58, i8* %62)
br label %64
64: ; preds = %56, %52
%65 = load i64, i64* %10
%66 = add nsw i64 %65, 1
store i64 %66, i64* %10
br label %35
67: ; preds = %35
%68 = load i32*, i32** %8
%69 = call i32 @fclose(i32* %68)
%70 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%71 = call i32 @unlink(i8* %70)
%72 = load i64, i64* %10
store i64 %72, i64* %3
br label %73
73: ; preds = %67, %29, %24
%74 = load i64, i64* %3
ret i64 %74
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/%ld.tmp\00"
@.str.1 = [72 x i8] c"cat /tmp/resolv.conf.auto | grep -v -e '^search ' -e ' 127.0.0.1$' > %s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [12 x i8] c"nameserver \00"
define i64 @osDnsSvrGet(i64 %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca [32 x i8]
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = icmp eq i8* %1, null
%10 = select i1 %9, i64 0, i64 %0
%11 = tail call i64 (...) @getpid()
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%14 = call i32 @osSystem(i8* %6)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %52
16: ; preds = %2
%17 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %52, label %19
19: ; preds = %16
%20 = shl i64 %10, 2
%21 = call i32 @osBZero(i8* %1, i64 %20)
%22 = call i32 @fgets(i8* %8, i32 128, i32* %17)
%23 = icmp eq i32 %22, 0
br i1 %23, label %48, label %24
24: ; preds = %19
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 11
br label %26
26: ; preds = %24, %44
%27 = phi i64 [ 0, %24 ], [ %45, %44 ]
br label %28
28: ; preds = %26, %32
%29 = call i32 @utilStrTrim(i8* %8)
%30 = load i8, i8* %8
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28, %35
%33 = call i32 @fgets(i8* %8, i32 128, i32* %17)
%34 = icmp eq i32 %33, 0
br i1 %34, label %48, label %28
35: ; preds = %28
%36 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 11)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %32
38: ; preds = %35
%39 = icmp ult i64 %27, %10
br i1 %39, label %40, label %44
40: ; preds = %38
%41 = shl nsw i64 %27, 2
%42 = getelementptr inbounds i8, i8* %1, i64 %41
%43 = call i32 @utilIpStr2Ip(i8* %25, i8* %42)
br label %44
44: ; preds = %40, %38
%45 = add nuw nsw i64 %27, 1
%46 = call i32 @fgets(i8* %8, i32 128, i32* %17)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %26
48: ; preds = %44, %32, %19
%49 = phi i64 [ 0, %19 ], [ %27, %32 ], [ %45, %44 ]
%50 = call i32 @fclose(i32* %17)
%51 = call i32 @unlink(i8* %7)
br label %52
52: ; preds = %16, %2, %48
%53 = phi i64 [ %49, %48 ], [ -1, %2 ], [ -1, %16 ]
ret i64 %53
}