#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
  int /*<<< orphan*/ h_addrtype;
};
typedef int /*<<< orphan*/ in_addr_t;
typedef int /*<<< orphan*/ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
int Set_address(char *addr, struct sockaddr_in *sin) {
  struct hostent *hp;
  bzero((char *)sin, sizeof(struct sockaddr));
  sin->sin_family = AF_INET;
  if ((sin->sin_addr.s_addr = inet_addr(addr)) == (in_addr_t)-1) {
    hp = gethostbyname(addr);
    if (!hp) {
      syslog(LOG_ERR, "unknown host %s", addr);
      return 1;
    }
    sin->sin_family = hp->h_addrtype;
    bcopy(hp->h_addr, (caddr_t)&sin->sin_addr, hp->h_length);
  }
  return 0;
}


x86 assembly (clang, -O0):
<Set_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1070 <bzero@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    -0x18(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    11f9 <Set_address+0xa9>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d3 <Set_address+0x83>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3e(%rip),%rsi
call   1050 <syslog@plt>
movl   $0x1,-0x4(%rbp)
jmp    1200 <Set_address+0xb0>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1060 <bcopy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Set_address>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x4,%esi
call   1070 <bzero@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    %r14,%rdi
call   1030 <inet_addr@plt>
mov    %eax,(%rbx)
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
jne    11c2 <Set_address+0x72>
mov    %r14,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     11a5 <Set_address+0x55>
mov    0x8(%rax),%ecx
mov    %ecx,0x4(%rbx)
mov    (%rax),%edx
mov    0x4(%rax),%edi
mov    %ebx,%esi
call   1060 <bcopy@plt>
jmp    11c2 <Set_address+0x72>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    %r14,%rdx
call   1050 <syslog@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32, i32 }
@AF_INET = global i32 0
@LOG_ERR = global i32 0
@.str = [16 x i8] c"unknown host %s\00"
define i32 @Set_address(i8* %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in*
%6 = alloca %struct.hostent*
store i8* %0, i8** %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
%7 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%8 = bitcast %struct.sockaddr_in* %7 to i8*
%9 = call i32 @bzero(i8* %8, i32 4)
%10 = load i32, i32* @AF_INET
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %10, i32* %12
%13 = load i8*, i8** %4
%14 = call i32 @inet_addr(i8* %13)
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %14, i32* %17
%18 = icmp eq i32 %14, -1
br i1 %18, label %19, label %44
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call %struct.hostent* @gethostbyname(i8* %20)
store %struct.hostent* %21, %struct.hostent** %6
%22 = load %struct.hostent*, %struct.hostent** %6
%23 = icmp ne %struct.hostent* %22, null
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i32, i32* @LOG_ERR
%26 = load i8*, i8** %4
%27 = call i32 @syslog(i32 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 1, i32* %3
br label %45
28: ; preds = %19
%29 = load %struct.hostent*, %struct.hostent** %6
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 2
%31 = load i32, i32* %30
%32 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %32, i32 0, i32 1
store i32 %31, i32* %33
%34 = load %struct.hostent*, %struct.hostent** %6
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 1
%36 = load i32, i32* %35
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %37, i32 0, i32 0
%39 = ptrtoint %struct.TYPE_2__* %38 to i32
%40 = load %struct.hostent*, %struct.hostent** %6
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 @bcopy(i32 %36, i32 %39, i32 %42)
br label %44
44: ; preds = %28, %2
store i32 0, i32* %3
br label %45
45: ; preds = %44, %24
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32, i32 }
@AF_INET = global i32 0
@LOG_ERR = global i32 0
@.str = [16 x i8] c"unknown host %s\00"
define i32 @Set_address(i8* %0, %struct.sockaddr_in* %1) {
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = tail call i32 @bzero(i8* %3, i32 4)
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %5, i32* %6
%7 = tail call i32 @inet_addr(i8* %0)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %7, i32* %8
%9 = icmp eq i32 %7, -1
br i1 %9, label %10, label %26
10: ; preds = %2
%11 = tail call %struct.hostent* @gethostbyname(i8* %0)
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @LOG_ERR
%15 = tail call i32 @syslog(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %26
16: ; preds = %10
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 2
%18 = load i32, i32* %17
store i32 %18, i32* %6
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 1
%20 = load i32, i32* %19
%21 = ptrtoint %struct.sockaddr_in* %1 to i64
%22 = trunc i64 %21 to i32
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 0
%24 = load i32, i32* %23
%25 = tail call i32 @bcopy(i32 %20, i32 %22, i32 %24)
br label %26
26: ; preds = %2, %16, %13
%27 = phi i32 [ 1, %13 ], [ 0, %16 ], [ 0, %2 ]
ret i32 %27
}