#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 hostent {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ perror(char *);
int pop(struct hostent *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int count, i = 0, port = 0, n = 0;
  struct hostent *he;
  FILE *fd;
  count = 0;
  if (argc != 3) {
    printf("usage: %s <host> <port>\n", argv[0]);
    exit(1);
  }
  if ((he = gethostbyname(argv[1])) == NULL) {
    perror("gethostbyname");
    exit(1);
  }
  if ((port = atoi(argv[2])) == 0)
    port = 110;
  while (pop(he, port, count) == 1) {
    count++;
  }
  printf("\n\nMy best score is %i\n", count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11bb <main+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ec <main+0x8c>
lea    0xe3c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    120c <main+0xac>
movl   $0x6e,-0x1c(%rbp)
jmp    1211 <main+0xb1>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <pop@plt>
cmp    $0x1,%eax
jne    1237 <main+0xd7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1211 <main+0xb1>
mov    -0x14(%rbp),%esi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11cb <main+0x6b>
mov    0x8(%rbx),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11e6 <main+0x86>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
mov    $0x6e,%ebx
cmovne %eax,%ebx
mov    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <pop@plt>
cmp    $0x1,%eax
je     11a0 <main+0x40>
lea    0xe6c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe2c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32 }
@.str = [25 x i8] c"usage: %s <host> <port>\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [23 x i8] c"\0A\0AMy best score is %i\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.hostent*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %6
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call %struct.hostent* @gethostbyname(i8* %23)
store %struct.hostent* %24, %struct.hostent** %10
%25 = icmp eq %struct.hostent* %24, null
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %8
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 110, i32* %8
br label %36
36: ; preds = %35, %29
br label %37
37: ; preds = %43, %36
%38 = load %struct.hostent*, %struct.hostent** %10
%39 = load i32, i32* %8
%40 = load i32, i32* %6
%41 = call i32 @pop(%struct.hostent* %38, i32 %39, i32 %40)
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %37
46: ; preds = %37
%47 = load i32, i32* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@.str = [25 x i8] c"usage: %s <host> <port>\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [23 x i8] c"\0A\0AMy best score is %i\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call %struct.hostent* @gethostbyname(i8* %10)
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 110, i32 %19
br label %22
22: ; preds = %22, %16
%23 = phi i32 [ 0, %16 ], [ %26, %22 ]
%24 = tail call i32 @pop(%struct.hostent* %11, i32 %21, i32 %23)
%25 = icmp eq i32 %24, 1
%26 = add nuw nsw i32 %23, 1
br i1 %25, label %22, label %27
27: ; preds = %22
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %23)
ret i32 0
}