#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 */
scalar_t__ getLocalHostIp(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *, int *);
int getLocalHostIpHex(char *ipHexBuf) {
  char ip[64] = {0};
  if (getLocalHostIp(ip) < 0 || ip[0] == '\0') {
    return -1;
  }
  int a[4];
  sscanf(ip, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
  sprintf(ipHexBuf, "%02x%02x%02x%02x", a[0], a[1], a[2], a[3]);
  return 0;
}


x86 assembly (clang, -O0):
<getLocalHostIpHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    -0x50(%rbp),%rdi
call   1030 <getLocalHostIp@plt>
cmp    $0x0,%rax
jl     117c <getLocalHostIpHex+0x3c>
movsbl -0x50(%rbp),%eax
cmp    $0x0,%eax
jne    1188 <getLocalHostIpHex+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <getLocalHostIpHex+0x99>
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    -0x60(%rbp),%rcx
add    $0x4,%rcx
lea    -0x60(%rbp),%r8
add    $0x8,%r8
lea    -0x60(%rbp),%r9
add    $0xc,%r9
lea    0xe51(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x60(%rbp),%edx
mov    -0x5c(%rbp),%ecx
mov    -0x58(%rbp),%r8d
mov    -0x54(%rbp),%r9d
lea    0xe3f(%rip),%rsi
call   1060 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLocalHostIpHex>:
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1030 <getLocalHostIp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     11b2 <getLocalHostIpHex+0x82>
cmpb   $0x0,0x10(%rsp)
je     11b2 <getLocalHostIpHex+0x82>
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0xe7d(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rsp,%rdx
call   1040 <sscanf@plt>
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%r9d
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
@.str.1 = [17 x i8] c"%02x%02x%02x%02x\00"
define i32 @getLocalHostIpHex(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [64 x i8]
%5 = alloca [4 x i32]
store i8* %0, i8** %3
%6 = bitcast [64 x i8]* %4 to i8*
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = call i64 @getLocalHostIp(i8* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10, %1
store i32 -1, i32* %2
br label %33
16: ; preds = %10
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%22 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %18, i32* %19, i32* %20, i32* %21)
%23 = load i8*, i8** %3
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%29 = load i32, i32* %28
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%31 = load i32, i32* %30
%32 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %27, i32 %29, i32 %31)
store i32 0, i32* %2
br label %33
33: ; preds = %16, %15
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
@.str.1 = [17 x i8] c"%02x%02x%02x%02x\00"
define i32 @getLocalHostIpHex(i8* nocapture writeonly %0) {
%2 = alloca [64 x i8]
%3 = alloca [4 x i32]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = call i64 @getLocalHostIp(i8* %4)
%6 = icmp slt i64 %5, 0
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %22, label %10
10: ; preds = %1
%11 = bitcast [4 x i32]* %3 to i8*
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%16 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %12, i32* %13, i32* %14, i32* %15)
%17 = load i32, i32* %12
%18 = load i32, i32* %13
%19 = load i32, i32* %14
%20 = load i32, i32* %15
%21 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18, i32 %19, i32 %20)
br label %22
22: ; preds = %1, %10
%23 = phi i32 [ 0, %10 ], [ -1, %1 ]
ret i32 %23
}