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

/* Variables and functions */
scalar_t__ isspace(char);
int parseOrigin(char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
char *strtok(char *, char *);
int getAsNumber(char *buffer, char *nextServer, int sizeSrv) {
  char *tok, *as, *serv;
  int num;
  tok = strtok(buffer, "\n");
  while (tok != NULL) {
    as = strstr(tok, "origin:");
    if (as != NULL) {
      num = parseOrigin(tok);
      if (num != 0) {
        return num;
      }
    }
    as = strstr(tok, "OriginAS:");
    if (as != NULL) {
      num = parseOrigin(tok);
      if (num != 0) {
        return num;
      }
    }
    serv = strstr(tok, "refer:");
    if ((serv != NULL)) {
      serv = serv + 7;
      while (isspace(*serv)) {
        serv++;
      }
      strncpy(nextServer, serv, sizeSrv);
    }
    serv = strstr(tok, "ReferralServer:");
    if ((serv != NULL)) {
      serv = serv + 16;
      while (isspace(*serv)) {
        serv++;
      }
      serv = serv + strlen("whois://");
      strncpy(nextServer, serv, sizeSrv);
    }
    tok = strtok(NULL, "\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<getAsNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     131d <getAsNumber+0x1bd>
mov    -0x28(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11d7 <getAsNumber+0x77>
mov    -0x28(%rbp),%rdi
call   1060 <parseOrigin@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11d2 <getAsNumber+0x72>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1324 <getAsNumber+0x1c4>
jmp    11d7 <getAsNumber+0x77>
mov    -0x28(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     121c <getAsNumber+0xbc>
mov    -0x28(%rbp),%rdi
call   1060 <parseOrigin@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1217 <getAsNumber+0xb7>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1324 <getAsNumber+0x1c4>
jmp    121c <getAsNumber+0xbc>
mov    -0x28(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     127e <getAsNumber+0x11e>
mov    -0x38(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     126e <getAsNumber+0x10e>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1247 <getAsNumber+0xe7>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xd92(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1304 <getAsNumber+0x1a4>
mov    -0x38(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     12d0 <getAsNumber+0x170>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12a9 <getAsNumber+0x149>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xd4c(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcf1(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1187 <getAsNumber+0x27>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAsNumber>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
lea    0xe88(%rip),%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     1296 <getAsNumber+0x136>
mov    %rax,%r13
lea    0xe72(%rip),%r14
lea    0xe69(%rip),%r12
jmp    11b8 <getAsNumber+0x58>
nopl   0x0(%rax)
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,%r13
test   %rax,%rax
je     129c <getAsNumber+0x13c>
mov    %r13,%rdi
mov    %r14,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11d8 <getAsNumber+0x78>
mov    %r13,%rdi
call   1060 <parseOrigin@plt>
test   %eax,%eax
jne    129a <getAsNumber+0x13a>
mov    %r13,%rdi
lea    0xe28(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11fc <getAsNumber+0x9c>
mov    %r13,%rdi
call   1060 <parseOrigin@plt>
test   %eax,%eax
jne    129a <getAsNumber+0x13a>
mov    %r13,%rdi
lea    0xe0e(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     1240 <getAsNumber+0xe0>
mov    %rax,%rbp
add    $0x6,%rbp
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
call   1050 <isspace@plt>
test   %rax,%rax
jne    1220 <getAsNumber+0xc0>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
mov    %r13,%rdi
lea    0xdd1(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11a0 <getAsNumber+0x40>
mov    %rax,%rbp
add    $0xf,%rbp
nop
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
call   1050 <isspace@plt>
test   %rax,%rax
jne    1260 <getAsNumber+0x100>
lea    0xdb2(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
jmp    11a0 <getAsNumber+0x40>
xor    %ebp,%ebp
jmp    129c <getAsNumber+0x13c>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [8 x i8] c"origin:\00"
@.str.2 = [10 x i8] c"OriginAS:\00"
@.str.3 = [7 x i8] c"refer:\00"
@.str.4 = [16 x i8] c"ReferralServer:\00"
@.str.5 = [9 x i8] c"whois://\00"
define i32 @getAsNumber(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %8
br label %14
14: ; preds = %89, %3
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %91
17: ; preds = %14
%18 = load i8*, i8** %8
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = load i8*, i8** %8
%24 = call i32 @parseOrigin(i8* %23)
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = load i32, i32* %11
store i32 %28, i32* %4
br label %92
29: ; preds = %22
br label %30
30: ; preds = %29, %17
%31 = load i8*, i8** %8
%32 = call i8* @strstr(i8* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i8* %32, i8** %9
%33 = load i8*, i8** %9
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %43
35: ; preds = %30
%36 = load i8*, i8** %8
%37 = call i32 @parseOrigin(i8* %36)
store i32 %37, i32* %11
%38 = load i32, i32* %11
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = load i32, i32* %11
store i32 %41, i32* %4
br label %92
42: ; preds = %35
br label %43
43: ; preds = %42, %30
%44 = load i8*, i8** %8
%45 = call i8* @strstr(i8* %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i8* %45, i8** %10
%46 = load i8*, i8** %10
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %64
48: ; preds = %43
%49 = load i8*, i8** %10
%50 = getelementptr inbounds i8, i8* %49, i64 7
store i8* %50, i8** %10
br label %51
51: ; preds = %56, %48
%52 = load i8*, i8** %10
%53 = load i8, i8* %52
%54 = call i64 @isspace(i8 signext %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i8*, i8** %10
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %10
br label %51
59: ; preds = %51
%60 = load i8*, i8** %6
%61 = load i8*, i8** %10
%62 = load i32, i32* %7
%63 = call i32 @strncpy(i8* %60, i8* %61, i32 %62)
br label %64
64: ; preds = %59, %43
%65 = load i8*, i8** %8
%66 = call i8* @strstr(i8* %65, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i8* %66, i8** %10
%67 = load i8*, i8** %10
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %89
69: ; preds = %64
%70 = load i8*, i8** %10
%71 = getelementptr inbounds i8, i8* %70, i64 16
store i8* %71, i8** %10
br label %72
72: ; preds = %77, %69
%73 = load i8*, i8** %10
%74 = load i8, i8* %73
%75 = call i64 @isspace(i8 signext %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i8*, i8** %10
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %10
br label %72
80: ; preds = %72
%81 = load i8*, i8** %10
%82 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
store i8* %84, i8** %10
%85 = load i8*, i8** %6
%86 = load i8*, i8** %10
%87 = load i32, i32* %7
%88 = call i32 @strncpy(i8* %85, i8* %86, i32 %87)
br label %89
89: ; preds = %80, %64
%90 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %90, i8** %8
br label %14
91: ; preds = %14
store i32 0, i32* %4
br label %92
92: ; preds = %91, %40, %27
%93 = load i32, i32* %4
ret i32 %93
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [8 x i8] c"origin:\00"
@.str.2 = [10 x i8] c"OriginAS:\00"
@.str.3 = [7 x i8] c"refer:\00"
@.str.4 = [16 x i8] c"ReferralServer:\00"
@.str.5 = [9 x i8] c"whois://\00"
define i32 @getAsNumber(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %51, label %6
6: ; preds = %3, %48
%7 = phi i8* [ %49, %48 ], [ %4, %3 ]
%8 = tail call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call i32 @parseOrigin(i8* %7)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %51
13: ; preds = %10, %6
%14 = tail call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i32 @parseOrigin(i8* %7)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %51
19: ; preds = %16, %13
%20 = tail call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %32, label %22
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %20, i64 7
br label %24
24: ; preds = %24, %22
%25 = phi i8* [ %23, %22 ], [ %29, %24 ]
%26 = load i8, i8* %25
%27 = tail call i64 @isspace(i8 signext %26)
%28 = icmp eq i64 %27, 0
%29 = getelementptr inbounds i8, i8* %25, i64 1
br i1 %28, label %30, label %24
30: ; preds = %24
%31 = tail call i32 @strncpy(i8* %1, i8* %25, i32 %2)
br label %32
32: ; preds = %30, %19
%33 = tail call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i8* %33, null
br i1 %34, label %48, label %35
35: ; preds = %32
%36 = getelementptr inbounds i8, i8* %33, i64 16
br label %37
37: ; preds = %37, %35
%38 = phi i8* [ %36, %35 ], [ %42, %37 ]
%39 = load i8, i8* %38
%40 = tail call i64 @isspace(i8 signext %39)
%41 = icmp eq i64 %40, 0
%42 = getelementptr inbounds i8, i8* %38, i64 1
br i1 %41, label %43, label %37
43: ; preds = %37
%44 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %38, i64 %45
%47 = tail call i32 @strncpy(i8* %1, i8* %46, i32 %2)
br label %48
48: ; preds = %43, %32
%49 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %6
51: ; preds = %10, %16, %48, %3
%52 = phi i32 [ 0, %3 ], [ 0, %48 ], [ %17, %16 ], [ %11, %10 ]
ret i32 %52
}