#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 */
struct in_addr {
  int s_addr;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int inet_addr(char *);
int /*<<< orphan*/ stderr;
unsigned int resolve(char *hostname) {
  static struct in_addr i;
  struct hostent *h;
  i.s_addr = inet_addr(hostname);
  if (i.s_addr == -1) {
    h = gethostbyname(hostname);
    if (h == NULL)
      fprintf(stderr, "cannot resolve %s\n", hostname);
    return 0;
    bcopy(h->h_addr, (char *)&i.s_addr, h->h_length);
  }
  return i.s_addr;
}


x86 assembly (clang, -O0):
<resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %eax,0x2ef1(%rip)
cmpl   $0xffffffff,0x2eea(%rip)
jne    1195 <resolve+0x65>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1189 <resolve+0x59>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    119e <resolve+0x6e>
mov    0x2ea1(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <inet_addr@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1169 <resolve+0x39>
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1169 <resolve+0x39>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32 }
@resolve.i = internal global %struct.in_addr zeroinitializer
@stderr = global i32 0
@.str = [19 x i8] c"cannot resolve %s\0A\00"
define i32 @resolve(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.hostent*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @inet_addr(i8* %5)
store i32 %6, i32* getelementptr inbounds (%struct.in_addr, %struct.in_addr* @resolve.i, i32 0, i32 0)
%7 = load i32, i32* getelementptr inbounds (%struct.in_addr, %struct.in_addr* @resolve.i, i32 0, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call %struct.hostent* @gethostbyname(i8* %10)
store %struct.hostent* %11, %struct.hostent** %4
%12 = load %struct.hostent*, %struct.hostent** %4
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %3
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %14, %9
store i32 0, i32* %2
br label %21
19: ; preds = %1
%20 = load i32, i32* getelementptr inbounds (%struct.in_addr, %struct.in_addr* @resolve.i, i32 0, i32 0)
store i32 %20, i32* %2
br label %21
21: ; preds = %19, %18
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.hostent = type { i32, i32 }
@stderr = global i32 0
@.str = [19 x i8] c"cannot resolve %s\0A\00"
define i32 @resolve(i8* %0) {
%2 = tail call i32 @inet_addr(i8* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = tail call %struct.hostent* @gethostbyname(i8* %0)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %1, %4, %7
%11 = phi i32 [ 0, %7 ], [ 0, %4 ], [ %2, %1 ]
ret i32 %11
}