#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 sockaddr_in {
  scalar_t__ sin_port;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_addr;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ caddr_t;
typedef int /*<<< orphan*/ CLIENT;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int RPC_ANYSOCK;
int atoi(char *);
int /*<<< orphan*/ *clnttcp_create(struct sockaddr_in *, int, int, int *,
                                   int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argn, char *argc[]) {
  int run_mode = 0;
  int test_status = 1;
  int progNum = atoi(argc[2]);
  CLIENT *clnt = NULL;
  struct sockaddr_in server_addr;
  struct hostent *hp = NULL;
  int sock = RPC_ANYSOCK;
  if ((hp = gethostbyname(argc[1])) == NULL) {
    fprintf(stderr, "can't get addr for %s\n", argc[1]);
    exit(-1);
  }
  memcpy((caddr_t)&server_addr.sin_addr, hp->h_addr, hp->h_length);
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = 0;
  clnt = clnttcp_create(&server_addr, progNum, 1, &sock, 0, 0);
  if (run_mode == 1) {
    printf("CLIENT : %p\n", clnt);
  }
  test_status = (clnt != NULL) ? 0 : 1;
  printf("%d\n", test_status);
  return test_status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1202 <main+0x92>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe0d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    -0x38(%rbp),%rax
add    $0xc,%rax
mov    %eax,%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1060 <memcpy@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x1c(%rbp),%esi
lea    -0x38(%rbp),%rdi
mov    $0x1,%edx
lea    -0x44(%rbp),%rcx
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1070 <clnttcp_create@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    126d <main+0xfd>
mov    -0x28(%rbp),%rax
mov    %eax,%esi
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd98(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x8(%rbx),%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1200 <main+0x90>
lea    0x8(%rsp),%rbx
lea    0xc(%rbx),%edi
mov    (%rax),%edx
mov    0x4(%rax),%esi
call   1060 <memcpy@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <clnttcp_create@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
lea    0xe27(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdec(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i64, i32, i32 }
%struct.hostent = type { i32, i32 }
@RPC_ANYSOCK = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"can't get addr for %s\0A\00"
@AF_INET = global i32 0
@.str.1 = [13 x i8] c"CLIENT : %p\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %7
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %8
store i32* null, i32** %9
store %struct.hostent* null, %struct.hostent** %11
%17 = load i32, i32* @RPC_ANYSOCK
store i32 %17, i32* %12
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call %struct.hostent* @gethostbyname(i8* %20)
store %struct.hostent* %21, %struct.hostent** %11
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %30
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %2
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
%32 = ptrtoint i32* %31 to i32
%33 = load %struct.hostent*, %struct.hostent** %11
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = load %struct.hostent*, %struct.hostent** %11
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @memcpy(i32 %32, i32 %35, i32 %38)
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %40, i32* %41
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i64 0, i64* %42
%43 = load i32, i32* %8
%44 = call i32* @clnttcp_create(%struct.sockaddr_in* %10, i32 %43, i32 1, i32* %12, i32 0, i32 0)
store i32* %44, i32** %9
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %51
47: ; preds = %30
%48 = load i32*, i32** %9
%49 = ptrtoint i32* %48 to i32
%50 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %47, %30
%52 = load i32*, i32** %9
%53 = icmp ne i32* %52, null
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 0, i32 1
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %7
ret i32 %58
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i64, i32, i32 }
%struct.hostent = type { i32, i32 }
@RPC_ANYSOCK = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"can't get addr for %s\0A\00"
@AF_INET = global i32 0
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = load i32, i32* @RPC_ANYSOCK
store i32 %10, i32* %4
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call %struct.hostent* @gethostbyname(i8* %12)
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %11
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%22 = ptrtoint i32* %21 to i64
%23 = trunc i64 %22 to i32
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i64 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @memcpy(i32 %23, i32 %25, i32 %27)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i64 0, i64* %31
%32 = call i32* @clnttcp_create(%struct.sockaddr_in* %3, i32 %7, i32 1, i32* %4, i32 0, i32 0)
%33 = icmp eq i32* %32, null
%34 = zext i1 %33 to i32
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
ret i32 %34
}