#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 */

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
size_t gotchar(char, char const *);
scalar_t__ run_command(char *, char **);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char const *);
void get_local_ip(char *ip_result) {
  unsigned char *res = NULL;
  if (run_command("ifconfig eth0 | grep inet | awk '{print $2}'",
                  (char **)&res)) {
    res[gotchar('\n', (const char *)res)] = 0;
    res[gotchar('\r', (const char *)res)] = 0;
    strcpy(ip_result,
           (strlen((const char *)res) != 0) ? (char *)res : "0.0.0.0");
  } else {
    strcpy(ip_result, "0.0.0.0");
  }
  if (!res) {
    free(res);
    res = NULL;
  }
}


x86 assembly (clang, -O0):
<get_local_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe95(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <run_command@plt>
cmp    $0x0,%rax
je     120a <get_local_ip+0xba>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1060 <gotchar@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0xd,%edi
call   1060 <gotchar@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     11e8 <get_local_ip+0x98>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11f8 <get_local_ip+0xa8>
lea    0xe3e(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11f8 <get_local_ip+0xa8>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    121a <get_local_ip+0xca>
mov    -0x8(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1040 <strcpy@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1236 <get_local_ip+0xe6>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_local_ip>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movq   $0x0,(%rsp)
lea    0xeaa(%rip),%rdi
mov    %rsp,%rsi
call   1060 <run_command@plt>
test   %rax,%rax
je     11a1 <get_local_ip+0x61>
mov    (%rsp),%rbx
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <gotchar@plt>
movb   $0x0,(%rbx,%rax,1)
mov    (%rsp),%rbx
mov    $0xd,%edi
mov    %rbx,%rsi
call   1050 <gotchar@plt>
movb   $0x0,(%rbx,%rax,1)
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
lea    0xe92(%rip),%rsi
cmovne %rax,%rsi
jmp    11a8 <get_local_ip+0x68>
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
cmpq   $0x0,(%rsp)
jne    11be <get_local_ip+0x7e>
xor    %edi,%edi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [45 x i8] c"ifconfig eth0 | grep inet | awk '{print $2}'\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
define void @get_local_ip(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = call i64 @run_command(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8** %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %25
6: ; preds = %1
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @gotchar(i8 signext 10, i8* %8)
%10 = getelementptr inbounds i8, i8* %7, i64 %9
store i8 0, i8* %10
%11 = load i8*, i8** %3
%12 = load i8*, i8** %3
%13 = call i64 @gotchar(i8 signext 13, i8* %12)
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 0, i8* %14
%15 = load i8*, i8** %2
%16 = load i8*, i8** %3
%17 = call i64 @strlen(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %6
%20 = load i8*, i8** %3
br label %22
21: ; preds = %6
br label %22
22: ; preds = %21, %19
%23 = phi i8* [ %20, %19 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %21 ]
%24 = call i32 @strcpy(i8* %15, i8* %23)
br label %28
25: ; preds = %1
%26 = load i8*, i8** %2
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %22
%29 = load i8*, i8** %3
%30 = icmp ne i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = call i32 @free(i8* %32)
store i8* null, i8** %3
br label %34
34: ; preds = %31, %28
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"ifconfig eth0 | grep inet | awk '{print $2}'\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
define void @get_local_ip(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = call i64 @run_command(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8** %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i64 @gotchar(i8 signext 10, i8* %7)
%9 = getelementptr inbounds i8, i8* %7, i64 %8
store i8 0, i8* %9
%10 = load i8*, i8** %2
%11 = call i64 @gotchar(i8 signext 13, i8* %10)
%12 = getelementptr inbounds i8, i8* %10, i64 %11
store i8 0, i8* %12
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %13
br label %17
17: ; preds = %1, %6
%18 = phi i8* [ %16, %6 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %1 ]
%19 = call i32 @strcpy(i8* %0, i8* %18)
%20 = load i8*, i8** %2
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @free(i8* null)
br label %24
24: ; preds = %22, %17
ret void
}