#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 *);
scalar_t__ run_command(char *, char **);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char const *);
void get_public_ip(char *ip_result) {
  unsigned char *res = NULL;
  if (run_command("curl --max-time 10 -s bot.whatismyipaddress.com",
                  (char **)&res)) {
    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_public_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xea5(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <run_command@plt>
cmp    $0x0,%rax
je     11b8 <get_public_ip+0x78>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     1196 <get_public_ip+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11a6 <get_public_ip+0x66>
lea    0xe93(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11a6 <get_public_ip+0x66>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11c8 <get_public_ip+0x88>
mov    -0x8(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1040 <strcpy@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11e4 <get_public_ip+0xa4>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_public_ip>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0xeb8(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <run_command@plt>
test   %rax,%rax
je     116c <get_public_ip+0x3c>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
lea    0xeca(%rip),%rsi
cmovne %rax,%rsi
jmp    1173 <get_public_ip+0x43>
lea    0xebd(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
cmpq   $0x0,0x8(%rsp)
jne    118a <get_public_ip+0x5a>
xor    %edi,%edi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [48 x i8] c"curl --max-time 10 -s bot.whatismyipaddress.com\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
define void @get_public_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 ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8** %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = load i8*, i8** %3
br label %14
13: ; preds = %6
br label %14
14: ; preds = %13, %11
%15 = phi i8* [ %12, %11 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %13 ]
%16 = call i32 @strcpy(i8* %7, i8* %15)
br label %20
17: ; preds = %1
%18 = load i8*, i8** %2
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %14
%21 = load i8*, i8** %3
%22 = icmp ne i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
store i8* null, i8** %3
br label %26
26: ; preds = %23, %20
ret void
}

LLVM IR (-O2):
@.str = [48 x i8] c"curl --max-time 10 -s bot.whatismyipaddress.com\00"
@.str.1 = [8 x i8] c"0.0.0.0\00"
define void @get_public_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 ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8** %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7
br label %11
11: ; preds = %1, %6
%12 = phi i8* [ %10, %6 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %1 ]
%13 = call i32 @strcpy(i8* %0, i8* %12)
%14 = load i8*, i8** %2
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @free(i8* null)
br label %18
18: ; preds = %16, %11
ret void
}