#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*/ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_NONE;
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)) == INADDR_NONE) {
    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)
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%eax
jne    11ff <Set_address+0xaf>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d9 <Set_address+0x89>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe38(%rip),%rsi
call   1050 <syslog@plt>
movl   $0x1,-0x4(%rbp)
jmp    1206 <Set_address+0xb6>
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)
mov    0x2e5c(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%eax
jne    11c8 <Set_address+0x78>
mov    %r14,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     11ab <Set_address+0x5b>
mov    0x8(%rax),%ecx
mov    %ecx,0x4(%rbx)
mov    (%rax),%edx
mov    0x4(%rax),%edi
mov    %ebx,%esi
call   1060 <bcopy@plt>
jmp    11c8 <Set_address+0x78>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%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
@INADDR_NONE = 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 = load i32, i32* @INADDR_NONE
%19 = icmp eq i32 %14, %18
br i1 %19, label %20, label %45
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = call %struct.hostent* @gethostbyname(i8* %21)
store %struct.hostent* %22, %struct.hostent** %6
%23 = load %struct.hostent*, %struct.hostent** %6
%24 = icmp ne %struct.hostent* %23, null
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = load i32, i32* @LOG_ERR
%27 = load i8*, i8** %4
%28 = call i32 @syslog(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %46
29: ; preds = %20
%30 = load %struct.hostent*, %struct.hostent** %6
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i32 0, i32 2
%32 = load i32, i32* %31
%33 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %33, i32 0, i32 1
store i32 %32, i32* %34
%35 = load %struct.hostent*, %struct.hostent** %6
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %35, i32 0, i32 1
%37 = load i32, i32* %36
%38 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %38, i32 0, i32 0
%40 = ptrtoint %struct.TYPE_2__* %39 to i32
%41 = load %struct.hostent*, %struct.hostent** %6
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @bcopy(i32 %37, i32 %40, i32 %43)
br label %45
45: ; preds = %29, %2
store i32 0, i32* %3
br label %46
46: ; preds = %45, %25
%47 = load i32, i32* %3
ret i32 %47
}

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
@INADDR_NONE = 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 = load i32, i32* @INADDR_NONE
%10 = icmp eq i32 %7, %9
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = tail call %struct.hostent* @gethostbyname(i8* %0)
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @LOG_ERR
%16 = tail call i32 @syslog(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %27
17: ; preds = %11
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 2
%19 = load i32, i32* %18
store i32 %19, i32* %6
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 1
%21 = load i32, i32* %20
%22 = ptrtoint %struct.sockaddr_in* %1 to i64
%23 = trunc i64 %22 to i32
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 0
%25 = load i32, i32* %24
%26 = tail call i32 @bcopy(i32 %21, i32 %23, i32 %25)
br label %27
27: ; preds = %2, %17, %14
%28 = phi i32 [ 1, %14 ], [ 0, %17 ], [ 0, %2 ]
ret i32 %28
}