#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 */
typedef int /*<<< orphan*/ uint32_t;
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
scalar_t__ parseip(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ taskstate(char *);
int netlookup(char *name, uint32_t *ip) {
  struct hostent *he;
  if (parseip(name, ip) >= 0)
    return 0;
  taskstate("netlookup");
  if ((he = gethostbyname(name)) != 0) {
    *ip = *(uint32_t *)he->h_addr;
    taskstate("netlookup succeeded");
    return 0;
  }
  taskstate("netlookup failed");
  return -1;
}


x86 assembly (clang, -O0):
<netlookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <parseip@plt>
cmp    $0x0,%rax
jl     1163 <netlookup+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <netlookup+0x90>
lea    0xe96(%rip),%rdi
call   1030 <taskstate@plt>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ad <netlookup+0x7d>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
lea    0xe6e(%rip),%rdi
call   1030 <taskstate@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <netlookup+0x90>
lea    0xe6a(%rip),%rdi
call   1030 <taskstate@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netlookup>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <parseip@plt>
xor    %ebp,%ebp
test   %rax,%rax
jns    1183 <netlookup+0x53>
lea    0xeb3(%rip),%rdi
call   1030 <taskstate@plt>
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1172 <netlookup+0x42>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %ebp,%ebp
lea    0xe9a(%rip),%rdi
jmp    117e <netlookup+0x4e>
mov    $0xffffffff,%ebp
lea    0xea0(%rip),%rdi
call   1030 <taskstate@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64 }
@.str = [10 x i8] c"netlookup\00"
@.str.1 = [20 x i8] c"netlookup succeeded\00"
@.str.2 = [17 x i8] c"netlookup failed\00"
define i32 @netlookup(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.hostent*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = load i32*, i32** %5
%9 = call i64 @parseip(i8* %7, i32* %8)
%10 = icmp sge i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %27
12: ; preds = %2
%13 = call i32 @taskstate(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %4
%15 = call %struct.hostent* @gethostbyname(i8* %14)
store %struct.hostent* %15, %struct.hostent** %6
%16 = icmp ne %struct.hostent* %15, null
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = load %struct.hostent*, %struct.hostent** %6
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = inttoptr i64 %20 to i32*
%22 = load i32, i32* %21
%23 = load i32*, i32** %5
store i32 %22, i32* %23
%24 = call i32 @taskstate(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %27
25: ; preds = %12
%26 = call i32 @taskstate(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
27: ; preds = %25, %17, %11
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.hostent = type { i64 }
@.str = [10 x i8] c"netlookup\00"
@.str.1 = [20 x i8] c"netlookup succeeded\00"
@.str.2 = [17 x i8] c"netlookup failed\00"
define i32 @netlookup(i8* %0, i32* %1) {
%3 = tail call i64 @parseip(i8* %0, i32* %1)
%4 = icmp sgt i64 %3, -1
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = tail call i32 @taskstate(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%7 = tail call %struct.hostent* @gethostbyname(i8* %0)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%11 = load i64, i64* %10
%12 = inttoptr i64 %11 to i32*
%13 = load i32, i32* %12
store i32 %13, i32* %1
br label %14
14: ; preds = %5, %9
%15 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %5 ]
%16 = phi i32 [ 0, %9 ], [ -1, %5 ]
%17 = tail call i32 @taskstate(i8* %15)
br label %18
18: ; preds = %14, %2
%19 = phi i32 [ 0, %2 ], [ %16, %14 ]
ret i32 %19
}