#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 */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
char *getLanIP(void) {
  static char buf[64];
  char *nl;
  FILE *fp;
  memset(buf, 0, sizeof(buf));
  if ((fp = popen("nvram_get 2860 lan_ipaddr", "r")) == NULL)
    goto error;
  if (!fgets(buf, sizeof(buf), fp)) {
    pclose(fp);
    goto error;
  }
  if (!strlen(buf)) {
    pclose(fp);
    goto error;
  }
  pclose(fp);
  if ((nl = strchr(buf, '\n')))
    *nl = '\0';
  return buf;
error:
  fprintf(stderr, "warning, cant find lan ip\n");
  return "10.10.10.254";
}


x86 assembly (clang, -O0):
<getLanIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0x2ef1(%rip),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
lea    0xe6e(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b1 <getLanIP+0x41>
jmp    123f <getLanIP+0xcf>
mov    -0x18(%rbp),%rdx
lea    0x2eb4(%rip),%rdi
mov    $0x40,%esi
call   1070 <fgets@plt>
cmp    $0x0,%eax
jne    11dd <getLanIP+0x6d>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
jmp    123f <getLanIP+0xcf>
lea    0x2e8c(%rip),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    1200 <getLanIP+0x90>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
jmp    123f <getLanIP+0xcf>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
lea    0x2e60(%rip),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     122f <getLanIP+0xbf>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e3a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    125f <getLanIP+0xef>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xdda(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLanIP>:
push   %rbp
push   %r14
push   %rbx
lea    0x2ef5(%rip),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
lea    0xe72(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1090 <popen@plt>
test   %rax,%rax
je     11f6 <getLanIP+0x86>
mov    %rax,%rbx
lea    0x2ec7(%rip),%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %eax,%eax
je     11ee <getLanIP+0x7e>
lea    0x2eaf(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <pclose@plt>
test   %ebp,%ebp
je     11f6 <getLanIP+0x86>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1212 <getLanIP+0xa2>
movb   $0x0,(%rax)
jmp    1212 <getLanIP+0xa2>
mov    %rbx,%rdi
call   1050 <pclose@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xe23(%rip),%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@getLanIP.buf = internal global [64 x i8] zeroinitializer
@.str = [26 x i8] c"nvram_get 2860 lan_ipaddr\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"warning, cant find lan ip\0A\00"
@.str.3 = [13 x i8] c"10.10.10.254\00"
define i8* @getLanIP() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32*
%4 = call i32 @memset(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0), i32 0, i32 64)
%5 = call i32* @popen(i8* getelementptr inbounds ([26 x i8], [26 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** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
br label %29
8: ; preds = %0
%9 = load i32*, i32** %3
%10 = call i32 @fgets(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0), i32 64, i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32*, i32** %3
%14 = call i32 @pclose(i32* %13)
br label %29
15: ; preds = %8
%16 = call i32 @strlen(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32*, i32** %3
%20 = call i32 @pclose(i32* %19)
br label %29
21: ; preds = %15
%22 = load i32*, i32** %3
%23 = call i32 @pclose(i32* %22)
%24 = call i8* @strchr(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0), i8 signext 10)
store i8* %24, i8** %2
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = load i8*, i8** %2
store i8 0, i8* %27
br label %28
28: ; preds = %26, %21
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0), i8** %1
br label %32
29: ; preds = %18, %12, %7
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %32
32: ; preds = %29, %28
%33 = load i8*, i8** %1
ret i8* %33
}

LLVM IR (-O2):
@getLanIP.buf = internal global [64 x i8] zeroinitializer
@.str = [26 x i8] c"nvram_get 2860 lan_ipaddr\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"warning, cant find lan ip\0A\00"
@.str.3 = [13 x i8] c"10.10.10.254\00"
define i8* @getLanIP() {
%1 = tail call i32 @memset(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0), i32 0, i32 64)
%2 = tail call i32* @popen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %17, label %4
4: ; preds = %0
%5 = tail call i32 @fgets(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0), i32 64, i32* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @pclose(i32* %2)
br label %17
9: ; preds = %4
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
%12 = tail call i32 @pclose(i32* %2)
br i1 %11, label %17, label %13
13: ; preds = %9
%14 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0), i8 signext 10)
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %13
store i8 0, i8* %14
br label %20
17: ; preds = %9, %0, %7
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %13, %16, %17
%21 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), %17 ], [ getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0), %16 ], [ getelementptr inbounds ([64 x i8], [64 x i8]* @getLanIP.buf, i64 0, i64 0), %13 ]
ret i8* %21
}