#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*/, struct in_addr *,
                         int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int inet_addr(char *);
int /*<<< orphan*/ stderr;
void get_ip_addr(struct in_addr *in_addr, char *str) {
  struct hostent *hostp;
  in_addr->s_addr = inet_addr(str);
  if (in_addr->s_addr == -1) {
    if ((hostp = gethostbyname(str)))
      bcopy(hostp->h_addr, in_addr, hostp->h_length);
    else {
      fprintf(stderr, "send_arp: unknown host %s\n", str);
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<get_ip_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    11d8 <get_ip_addr+0x88>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b0 <get_ip_addr+0x60>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1060 <bcopy@plt>
jmp    11d3 <get_ip_addr+0x83>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11d8 <get_ip_addr+0x88>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip_addr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <inet_addr@plt>
mov    %eax,(%rbx)
cmp    $0xffffffff,%eax
je     1171 <get_ip_addr+0x21>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1192 <get_ip_addr+0x42>
mov    (%rax),%edx
mov    0x4(%rax),%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <bcopy@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32 }
@stderr = global i32 0
@.str = [27 x i8] c"send_arp: unknown host %s\0A\00"
define void @get_ip_addr(%struct.in_addr* %0, i8* %1) {
%3 = alloca %struct.in_addr*
%4 = alloca i8*
%5 = alloca %struct.hostent*
store %struct.in_addr* %0, %struct.in_addr** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i32 @inet_addr(i8* %6)
%8 = load %struct.in_addr*, %struct.in_addr** %3
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
store i32 %7, i32* %9
%10 = load %struct.in_addr*, %struct.in_addr** %3
%11 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %33
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call %struct.hostent* @gethostbyname(i8* %15)
store %struct.hostent* %16, %struct.hostent** %5
%17 = icmp ne %struct.hostent* %16, null
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load %struct.hostent*, %struct.hostent** %5
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load %struct.in_addr*, %struct.in_addr** %3
%23 = load %struct.hostent*, %struct.hostent** %5
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @bcopy(i32 %21, %struct.in_addr* %22, i32 %25)
br label %32
27: ; preds = %14
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %4
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %18
br label %33
33: ; preds = %32, %2
ret void
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32 }
@stderr = global i32 0
@.str = [27 x i8] c"send_arp: unknown host %s\0A\00"
define void @get_ip_addr(%struct.in_addr* %0, i8* %1) {
%3 = tail call i32 @inet_addr(i8* %1)
%4 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %0, i64 0, i32 0
store i32 %3, i32* %4
%5 = icmp eq i32 %3, -1
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = tail call %struct.hostent* @gethostbyname(i8* %1)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 @bcopy(i32 %11, %struct.in_addr* %0, i32 %13)
br label %19
15: ; preds = %6
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %1)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %9, %2
ret void
}