#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*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/);
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*/ 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;
  int nbCall = atoi(argc[3]);
  int nbOk = 0;
  int i;
  if ((hp = gethostbyname(argc[1])) == NULL) {
    fprintf(stderr, "can't get addr for %s\n", argc[1]);
    exit(-1);
  }
  bcopy(hp->h_addr, (caddr_t)&server_addr.sin_addr, hp->h_length);
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = 0;
  for (i = 0; i < nbCall; i++) {
    clnt = clnttcp_create(&server_addr, progNum, 1, &sock, 0, 0);
    if ((CLIENT *)clnt != NULL)
      nbOk++;
  }
  if (run_mode == 1) {
    printf("Aimed : %d\n", nbCall);
    printf("Got : %d\n", nbOk);
  }
  test_status = (nbOk == nbCall) ? 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    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1219 <main+0xa9>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf6(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x38(%rbp),%rax
add    $0xc,%rax
mov    %eax,%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1070 <bcopy@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    12a2 <main+0x132>
mov    -0x1c(%rbp),%esi
lea    -0x38(%rbp),%rdi
mov    $0x1,%edx
lea    -0x44(%rbp),%rcx
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1060 <clnttcp_create@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     128f <main+0x11f>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1294 <main+0x124>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1250 <main+0xe0>
cmpl   $0x1,-0x14(%rbp)
jne    12ca <main+0x15a>
mov    -0x48(%rbp),%esi
lea    0xd61(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4c(%rbp),%esi
lea    0xd5e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%esi
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd36(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    0x10(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r13d
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x18(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     124c <main+0xdc>
mov    (%rax),%edx
mov    0x4(%rax),%edi
lea    0x8(%rsp),%rsi
add    $0xc,%esi
call   1070 <bcopy@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
xor    %ebp,%ebp
test   %r14d,%r14d
jle    1225 <main+0xb5>
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
mov    %r14d,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
mov    %r12,%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <clnttcp_create@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0xffffffff,%ebx
jne    1200 <main+0x90>
xor    %ebx,%ebx
cmp    %r14d,%ebp
setne  %bl
lea    0xde3(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xda0(%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 = [12 x i8] c"Aimed : %d\0A\00"
@.str.2 = [10 x i8] c"Got : %d\0A\00"
@.str.3 = [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
%13 = alloca i32
%14 = alloca i32
%15 = 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
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %8
store i32* null, i32** %9
store %struct.hostent* null, %struct.hostent** %11
%20 = load i32, i32* @RPC_ANYSOCK
store i32 %20, i32* %12
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 3
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %13
store i32 0, i32* %14
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call %struct.hostent* @gethostbyname(i8* %27)
store %struct.hostent* %28, %struct.hostent** %11
%29 = icmp eq %struct.hostent* %28, null
br i1 %29, label %30, label %37
30: ; preds = %2
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %2
%38 = load %struct.hostent*, %struct.hostent** %11
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
%42 = ptrtoint i32* %41 to i32
%43 = load %struct.hostent*, %struct.hostent** %11
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @bcopy(i32 %40, i32 %42, i32 %45)
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %47, i32* %48
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i64 0, i64* %49
store i32 0, i32* %15
br label %50
50: ; preds = %63, %37
%51 = load i32, i32* %15
%52 = load i32, i32* %13
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %66
54: ; preds = %50
%55 = load i32, i32* %8
%56 = call i32* @clnttcp_create(%struct.sockaddr_in* %10, i32 %55, i32 1, i32* %12, i32 0, i32 0)
store i32* %56, i32** %9
%57 = load i32*, i32** %9
%58 = icmp ne i32* %57, null
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i32, i32* %14
%61 = add nsw i32 %60, 1
store i32 %61, i32* %14
br label %62
62: ; preds = %59, %54
br label %63
63: ; preds = %62
%64 = load i32, i32* %15
%65 = add nsw i32 %64, 1
store i32 %65, i32* %15
br label %50
66: ; preds = %50
%67 = load i32, i32* %6
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %74
69: ; preds = %66
%70 = load i32, i32* %13
%71 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %70)
%72 = load i32, i32* %14
%73 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %69, %66
%75 = load i32, i32* %14
%76 = load i32, i32* %13
%77 = icmp eq i32 %75, %76
%78 = zext i1 %77 to i64
%79 = select i1 %77, i32 0, i32 1
store i32 %79, i32* %7
%80 = load i32, i32* %7
%81 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %80)
%82 = load i32, i32* %7
ret i32 %82
}

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.3 = [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 3
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call %struct.hostent* @gethostbyname(i8* %15)
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %14
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %2
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%27 = ptrtoint i32* %26 to i64
%28 = trunc i64 %27 to i32
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @bcopy(i32 %25, i32 %28, i32 %30)
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i64 0, i64* %34
%35 = icmp sgt i32 %13, 0
br i1 %35, label %36, label %45
36: ; preds = %23, %36
%37 = phi i32 [ %43, %36 ], [ 0, %23 ]
%38 = phi i32 [ %42, %36 ], [ 0, %23 ]
%39 = call i32* @clnttcp_create(%struct.sockaddr_in* %3, i32 %7, i32 1, i32* %4, i32 0, i32 0)
%40 = icmp ne i32* %39, null
%41 = zext i1 %40 to i32
%42 = add nuw nsw i32 %38, %41
%43 = add nuw nsw i32 %37, 1
%44 = icmp eq i32 %43, %13
br i1 %44, label %45, label %36
45: ; preds = %36, %23
%46 = phi i32 [ 0, %23 ], [ %42, %36 ]
%47 = icmp ne i32 %46, %13
%48 = zext i1 %47 to i32
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %48)
ret i32 %48
}