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

/* Variables and functions */
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ iswhitespace(char);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ st_pop(struct forth_instance *);
int /*<<< orphan*/ st_push(struct forth_instance *, int);
void dnstoip(struct forth_instance *fi) {
  struct hostent *h;
  struct in_addr s;
  char back, *name, *dest;
  int i = 0;
  name = (char *)st_pop(fi);
  dest = (char *)st_pop(fi);
  memset(dest, '\0', 16);
  while (name[i] && !iswhitespace(name[i]))
    i++;
  back = name[i];
  name[i] = '\0';
  h = gethostbyname(name);
  name[i] = back;
  if (h == NULL) {
    st_push(fi, (int)0);
    return;
  }
  memcpy(&(s.s_addr), h->h_addr_list[0], h->h_length);
  snprintf(dest, 16, "%s", inet_ntoa(s));
  st_push(fi, (int)1);
  return;
}


x86 assembly (clang, -O0):
<dnstoip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <st_pop@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <st_pop@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x35(%rbp)
je     11f3 <dnstoip+0x73>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <iswhitespace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    1203 <dnstoip+0x83>
jmp    1211 <dnstoip+0x91>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11bd <dnstoip+0x3d>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
cmpq   $0x0,-0x10(%rbp)
jne    1261 <dnstoip+0xe1>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   10a0 <st_push@plt>
jmp    12b0 <dnstoip+0x130>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1090 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rcx
mov    $0x10,%esi
lea    0xd63(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <st_push@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dnstoip>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
call   1070 <st_pop@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1070 <st_pop@plt>
mov    %rax,%r14
xor    %ebx,%ebx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    (%r12),%al
test   %al,%al
je     11e2 <dnstoip+0x62>
xor    %ebx,%ebx
nopl   (%rax)
movsbl %al,%edi
call   1030 <iswhitespace@plt>
test   %eax,%eax
jne    11da <dnstoip+0x5a>
movzbl 0x1(%r12,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    11c0 <dnstoip+0x40>
mov    %ebx,%eax
mov    (%r12,%rax,1),%bpl
jmp    11e4 <dnstoip+0x64>
xor    %ebp,%ebp
mov    %ebx,%ebx
movb   $0x0,(%r12,%rbx,1)
mov    %r12,%rdi
call   1080 <gethostbyname@plt>
mov    %bpl,(%r12,%rbx,1)
test   %rax,%rax
je     1248 <dnstoip+0xc8>
mov    0x8(%rax),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
call   1090 <memcpy@plt>
mov    0x8(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xde2(%rip),%rdx
mov    %r14,%rdi
mov    $0x10,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   10a0 <st_push@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
xor    %esi,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <st_push@plt>

LLVM IR (-O0):
%struct.forth_instance = type { i32 }
%struct.hostent = type { i32, i32* }
%struct.in_addr = type { i32 }
@.str = [3 x i8] c"%s\00"
define void @dnstoip(%struct.forth_instance* %0) {
%2 = alloca %struct.forth_instance*
%3 = alloca %struct.hostent*
%4 = alloca %struct.in_addr
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store %struct.forth_instance* %0, %struct.forth_instance** %2
store i32 0, i32* %8
%9 = load %struct.forth_instance*, %struct.forth_instance** %2
%10 = call i64 @st_pop(%struct.forth_instance* %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load %struct.forth_instance*, %struct.forth_instance** %2
%13 = call i64 @st_pop(%struct.forth_instance* %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = call i32 @memset(i8* %15, i8 signext 0, i32 16)
br label %17
17: ; preds = %36, %1
%18 = load i8*, i8** %6
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %17
%26 = load i8*, i8** %6
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @iswhitespace(i8 signext %30)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
br label %34
34: ; preds = %25, %17
%35 = phi i1 [ false, %17 ], [ %33, %25 ]
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %17
39: ; preds = %34
%40 = load i8*, i8** %6
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
store i8 %44, i8* %5
%45 = load i8*, i8** %6
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %6
%50 = call %struct.hostent* @gethostbyname(i8* %49)
store %struct.hostent* %50, %struct.hostent** %3
%51 = load i8, i8* %5
%52 = load i8*, i8** %6
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 %51, i8* %55
%56 = load %struct.hostent*, %struct.hostent** %3
%57 = icmp eq %struct.hostent* %56, null
br i1 %57, label %58, label %61
58: ; preds = %39
%59 = load %struct.forth_instance*, %struct.forth_instance** %2
%60 = call i32 @st_push(%struct.forth_instance* %59, i32 0)
br label %79
61: ; preds = %39
%62 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%63 = load %struct.hostent*, %struct.hostent** %3
%64 = getelementptr inbounds %struct.hostent, %struct.hostent* %63, i32 0, i32 1
%65 = load i32*, i32** %64
%66 = getelementptr inbounds i32, i32* %65, i64 0
%67 = load i32, i32* %66
%68 = load %struct.hostent*, %struct.hostent** %3
%69 = getelementptr inbounds %struct.hostent, %struct.hostent* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i32 @memcpy(i32* %62, i32 %67, i32 %70)
%72 = load i8*, i8** %7
%73 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%74 = load i32, i32* %73
%75 = call i8* @inet_ntoa(i32 %74)
%76 = call i32 @snprintf(i8* %72, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %75)
%77 = load %struct.forth_instance*, %struct.forth_instance** %2
%78 = call i32 @st_push(%struct.forth_instance* %77, i32 1)
br label %79
79: ; preds = %61, %58
ret void
}

LLVM IR (-O2):
%struct.forth_instance = type { i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32* }
@.str = [3 x i8] c"%s\00"
define void @dnstoip(%struct.forth_instance* %0) {
%2 = alloca %struct.in_addr
%3 = bitcast %struct.in_addr* %2 to i8*
%4 = tail call i64 @st_pop(%struct.forth_instance* %0)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i64 @st_pop(%struct.forth_instance* %0)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @memset(i8* %7, i8 signext 0, i32 16)
%9 = load i8, i8* %5
%10 = icmp eq i8 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %1, %17
%12 = phi i64 [ %18, %17 ], [ 0, %1 ]
%13 = phi i8 [ %21, %17 ], [ %9, %1 ]
%14 = phi i32 [ %19, %17 ], [ 0, %1 ]
%15 = tail call i32 @iswhitespace(i8 signext %13)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = add nuw i64 %12, 1
%19 = add nuw nsw i32 %14, 1
%20 = getelementptr inbounds i8, i8* %5, i64 %18
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %25, label %11
23: ; preds = %11
%24 = trunc i64 %12 to i32
br label %25
25: ; preds = %17, %23
%26 = phi i32 [ %24, %23 ], [ %19, %17 ]
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %5, i64 %27
%29 = load i8, i8* %28
br label %30
30: ; preds = %1, %25
%31 = phi i8 [ %29, %25 ], [ 0, %1 ]
%32 = phi i32 [ %26, %25 ], [ 0, %1 ]
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %5, i64 %33
store i8 0, i8* %34
%35 = tail call %struct.hostent* @gethostbyname(i8* %5)
store i8 %31, i8* %34
%36 = icmp eq %struct.hostent* %35, null
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = tail call i32 @st_push(%struct.forth_instance* %0, i32 0)
br label %51
39: ; preds = %30
%40 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %35, i64 0, i32 1
%42 = load i32*, i32** %41
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %35, i64 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @memcpy(i32* %40, i32 %43, i32 %45)
%47 = load i32, i32* %40
%48 = call i8* @inet_ntoa(i32 %47)
%49 = call i32 @snprintf(i8* %7, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %48)
%50 = call i32 @st_push(%struct.forth_instance* %0, i32 1)
br label %51
51: ; preds = %39, %37
ret void
}