#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 menu_s {
  int dummy;
};
typedef int /*<<< orphan*/ ip;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ menu_display_error(struct menu_s *, int, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
void config_display_ip(struct menu_s *parent, int displayfd, int arg) {
  char ip[32];
  FILE *fp;
  char *cmd = "ifconfig eth0 | sed -e '/inet addr/pd' | "
              "sed -e 's/^.*inet addr://' | sed -e 's/ .*$//' > /tmp/myip";
  system(cmd);
  fp = fopen("/tmp/myip", "r");
  if (fp != NULL && fgets(ip, sizeof(ip), fp) != NULL && strlen(ip) > 0) {
    ip[strlen(ip) - 1] = '\0';
  } else
    strcpy(ip, "unknown");
  menu_display_error(parent, displayfd, "Current IP", ip);
}


x86 assembly (clang, -O0):
<config_display_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xe87(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <system@plt>
lea    0xecd(%rip),%rdi
lea    0xed0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11ee <config_display_ip+0x8e>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x20,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     11ee <config_display_ip+0x8e>
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jle    11ee <config_display_ip+0x8e>
lea    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
jmp    11fe <config_display_ip+0x9e>
lea    -0x30(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rcx
lea    0xe5e(%rip),%rdx
call   1040 <menu_display_error@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_display_ip>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe8c(%rip),%rdi
call   1060 <system@plt>
lea    0xeda(%rip),%rdi
lea    0xedd(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c7 <config_display_ip+0x67>
mov    %rsp,%rdi
mov    $0x20,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11c7 <config_display_ip+0x67>
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11c7 <config_display_ip+0x67>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
jmp    11d6 <config_display_ip+0x76>
lea    0xe98(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0xe91(%rip),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <menu_display_error@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.menu_s = type { i32 }
@.str = [100 x i8] c"ifconfig eth0 | sed -e '/inet addr/pd' | sed -e 's/^.*inet addr://' | sed -e 's/ .*$//' > /tmp/myip\00"
@.str.1 = [10 x i8] c"/tmp/myip\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"unknown\00"
@.str.4 = [11 x i8] c"Current IP\00"
define void @config_display_ip(%struct.menu_s* %0, i32 %1, i32 %2) {
%4 = alloca %struct.menu_s*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca i32*
%9 = alloca i8*
store %struct.menu_s* %0, %struct.menu_s** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %9
%11 = call i32 @system(i8* %10)
%12 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %30
15: ; preds = %3
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%17 = load i32*, i32** %8
%18 = call i32* @fgets(i8* %16, i32 32, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %28
store i8 0, i8* %29
br label %33
30: ; preds = %20, %15, %3
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%32 = call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %30, %24
%34 = load %struct.menu_s*, %struct.menu_s** %4
%35 = load i32, i32* %5
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%37 = call i32 @menu_display_error(%struct.menu_s* %34, i32 %35, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %36)
ret void
}

LLVM IR (-O2):
%struct.menu_s = type { i32 }
@.str = [100 x i8] c"ifconfig eth0 | sed -e '/inet addr/pd' | sed -e 's/^.*inet addr://' | sed -e 's/ .*$//' > /tmp/myip\00"
@.str.1 = [10 x i8] c"/tmp/myip\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"unknown\00"
@.str.4 = [11 x i8] c"Current IP\00"
define void @config_display_ip(%struct.menu_s* %0, i32 %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @system(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %20, label %9
9: ; preds = %3
%10 = call i32* @fgets(i8* %5, i32 32, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = call i32 @strlen(i8* %5)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = call i32 @strlen(i8* %5)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
br label %22
20: ; preds = %12, %9, %3
%21 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = call i32 @menu_display_error(%struct.menu_s* %0, i32 %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %5)
ret void
}