#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__ GetHostName(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int get_ip_address(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
int /*<<< orphan*/ stderr;
char *get_own_ip_address() {
  int ipaddr;
  int b0, b1, b2, b3;
  char buf[1024];
  char *ip = NULL;
  if ((ip = (char *)malloc(1024)) == NULL) {
    fprintf(stderr, "Can't malloc in get_own_ip_address\n");
    exit(1);
  }
  if (GetHostName(buf, sizeof buf)) {
    fprintf(stderr, "Can't find hostname\n");
    return (NULL);
  }
  ipaddr = get_ip_address(buf);
  b0 = ipaddr >> 24;
  b1 = ipaddr >> 16;
  b2 = ipaddr >> 8;
  b3 = ipaddr;
  b0 &= 255;
  b1 &= 255;
  b2 &= 255;
  b3 &= 255;
  sprintf(ip, "%d.%d.%d.%d", b0, b1, b2, b3);
  return (ip);
}


x86 assembly (clang, -O0):
<get_own_ip_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movq   $0x0,-0x428(%rbp)
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    11b0 <get_own_ip_address+0x50>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1050 <GetHostName@plt>
cmp    $0x0,%rax
je     11ed <get_own_ip_address+0x8d>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1275 <get_own_ip_address+0x115>
lea    -0x420(%rbp),%rdi
call   1060 <get_ip_address@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x18,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x428(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0xdd4(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_own_ip_address>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    $0x400,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11e1 <get_own_ip_address+0x81>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1050 <GetHostName@plt>
test   %rax,%rax
je     11a6 <get_own_ip_address+0x46>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1030 <fprintf@plt>
xor    %ebx,%ebx
jmp    11d4 <get_own_ip_address+0x74>
mov    %rsp,%rdi
call   1060 <get_ip_address@plt>
mov    %eax,%ecx
movzbl %ah,%ebp
movzbl %al,%r9d
mov    %eax,%edx
shr    $0x18,%edx
shr    $0x10,%ecx
movzbl %cl,%ecx
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%r8d
call   1070 <sprintf@plt>
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Can't malloc in get_own_ip_address\0A\00"
@.str.1 = [21 x i8] c"Can't find hostname\0A\00"
@.str.2 = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @get_own_ip_address() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i8*
store i8* null, i8** %8
%9 = call i64 @malloc(i32 1024)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %8
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = call i64 @GetHostName(i8* %17, i32 1024)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %1
br label %48
23: ; preds = %16
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%25 = call i32 @get_ip_address(i8* %24)
store i32 %25, i32* %2
%26 = load i32, i32* %2
%27 = ashr i32 %26, 24
store i32 %27, i32* %3
%28 = load i32, i32* %2
%29 = ashr i32 %28, 16
store i32 %29, i32* %4
%30 = load i32, i32* %2
%31 = ashr i32 %30, 8
store i32 %31, i32* %5
%32 = load i32, i32* %2
store i32 %32, i32* %6
%33 = load i32, i32* %3
%34 = and i32 %33, 255
store i32 %34, i32* %3
%35 = load i32, i32* %4
%36 = and i32 %35, 255
store i32 %36, i32* %4
%37 = load i32, i32* %5
%38 = and i32 %37, 255
store i32 %38, i32* %5
%39 = load i32, i32* %6
%40 = and i32 %39, 255
store i32 %40, i32* %6
%41 = load i8*, i8** %8
%42 = load i32, i32* %3
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = load i32, i32* %6
%46 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %43, i32 %44, i32 %45)
%47 = load i8*, i8** %8
store i8* %47, i8** %1
br label %48
48: ; preds = %23, %20
%49 = load i8*, i8** %1
ret i8* %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Can't malloc in get_own_ip_address\0A\00"
@.str.1 = [21 x i8] c"Can't find hostname\0A\00"
@.str.2 = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @get_own_ip_address() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i64 @malloc(i32 1024)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i64 @GetHostName(i8* %2, i32 1024)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %25
16: ; preds = %10
%17 = call i32 @get_ip_address(i8* %2)
%18 = lshr i32 %17, 24
%19 = lshr i32 %17, 16
%20 = lshr i32 %17, 8
%21 = and i32 %19, 255
%22 = and i32 %20, 255
%23 = and i32 %17, 255
%24 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %21, i32 %22, i32 %23)
br label %25
25: ; preds = %16, %13
%26 = phi i8* [ null, %13 ], [ %4, %16 ]
ret i8* %26
}