#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 */
typedef int /*<<< orphan*/ server;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int getAsNumber(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ whois_query(char *, char *, char **);
int asLookup(char *ip) {
  char *response = NULL;
  int asNum = 0;
  char server[256];
  int i = 0;
  strcpy(server, "whois.iana.org\0");
  while (asNum == 0 && i <= 3) {
    i++;
    if (whois_query(server, ip, &response)) {
      free(response);
      return 0;
    }
    asNum = getAsNumber(response, server, sizeof(server));
  }
  free(response);
  return asNum;
}


x86 assembly (clang, -O0):
<asLookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <strcpy@plt>
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x125(%rbp)
jne    119d <asLookup+0x5d>
cmpl   $0x3,-0x124(%rbp)
setle  %al
mov    %al,-0x125(%rbp)
mov    -0x125(%rbp),%al
test   $0x1,%al
jne    11b0 <asLookup+0x70>
jmp    120f <asLookup+0xcf>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <whois_query@plt>
cmp    $0x0,%rax
je     11f2 <asLookup+0xb2>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    121e <asLookup+0xde>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <getAsNumber@plt>
mov    %eax,-0x1c(%rbp)
jmp    117b <asLookup+0x3b>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asLookup>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
lea    0xe9e(%rip),%rsi
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1050 <strcpy@plt>
xor    %ebx,%ebx
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <whois_query@plt>
test   %rax,%rax
jne    11b7 <asLookup+0x77>
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   1060 <getAsNumber@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11b9 <asLookup+0x79>
lea    0x1(%rbx),%eax
cmp    $0x3,%ebx
mov    %eax,%ebx
jb     1180 <asLookup+0x40>
jmp    11b9 <asLookup+0x79>
xor    %ebp,%ebp
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"whois.iana.org\00\00"
define i32 @asLookup(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %4
store i32 0, i32* %5
store i32 0, i32* %7
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %28, %1
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %7
%15 = icmp sle i32 %14, 3
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ false, %10 ], [ %15, %13 ]
br i1 %17, label %18, label %32
18: ; preds = %16
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i64 @whois_query(i8* %21, i8* %22, i8** %4)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i8*, i8** %4
%27 = call i32 @free(i8* %26)
store i32 0, i32* %2
br label %36
28: ; preds = %18
%29 = load i8*, i8** %4
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%31 = call i32 @getAsNumber(i8* %29, i8* %30, i32 256)
store i32 %31, i32* %5
br label %10
32: ; preds = %16
%33 = load i8*, i8** %4
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* %5
store i32 %35, i32* %2
br label %36
36: ; preds = %32, %25
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [16 x i8] c"whois.iana.org\00\00"
define i32 @asLookup(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %1, %11
%8 = phi i32 [ 0, %1 ], [ %12, %11 ]
%9 = call i64 @whois_query(i8* %5, i8* %0, i8** %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = add nuw nsw i32 %8, 1
%13 = load i8*, i8** %2
%14 = call i32 @getAsNumber(i8* %13, i8* %5, i32 256)
%15 = icmp eq i32 %14, 0
%16 = icmp ult i32 %8, 3
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %7, label %18
18: ; preds = %11, %7
%19 = phi i32 [ 0, %7 ], [ %14, %11 ]
%20 = load i8*, i8** %2
%21 = call i32 @free(i8* %20)
ret i32 %19
}