#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 */
int /*<<< orphan*/ FreeSplitList(char **);
int /*<<< orphan*/ find_domain_no_www(char const *, char *, int);
scalar_t__ isSecondLevelDomain(char *);
int /*<<< orphan*/ printf(char *, char const *, int);
int split(char *, char *, char ***);
int /*<<< orphan*/ strlcat(char *, char *, int);
int strlen(char *);
int find_domain_no_subname(const char url[], char domain[], int sizeofdomain) {
  char **Data;
  int TokCount;
  int i;
  int nrToGet;
  if (!find_domain_no_www(url, domain, sizeofdomain)) {
    return 0;
  }
  TokCount = split(domain, ".", &Data);
  domain[0] = '\0';
  if (isSecondLevelDomain(Data[TokCount - 1])) {
    nrToGet = 3;
  } else {
    nrToGet = 2;
  }
  if (TokCount < nrToGet) {
    printf("bad domain url: \"%s\", nr %i\n", url, TokCount);
    return 0;
  }
  for (i = nrToGet; i > 0; i--) {
    strlcat(domain, Data[TokCount - i], sizeofdomain);
    strlcat(domain, ".", sizeofdomain);
  }
  domain[strlen(domain) - 1] = '\0';
  FreeSplitList(Data);
  return 1;
}


x86 assembly (clang, -O0):
<find_domain_no_subname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <find_domain_no_www@plt>
cmp    $0x0,%eax
jne    11a8 <find_domain_no_subname+0x38>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <find_domain_no_subname+0x133>
mov    -0x18(%rbp),%rdi
lea    0xe4d(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1090 <split@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <isSecondLevelDomain@plt>
cmp    $0x0,%rax
je     11f2 <find_domain_no_subname+0x82>
movl   $0x3,-0x34(%rbp)
jmp    11f9 <find_domain_no_subname+0x89>
movl   $0x2,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1224 <find_domain_no_subname+0xb4>
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xdef(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <find_domain_no_subname+0x133>
mov    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    1272 <find_domain_no_subname+0x102>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    -0x30(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strlcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xda1(%rip),%rsi
call   1040 <strlcat@plt>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    122a <find_domain_no_subname+0xba>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1070 <FreeSplitList@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_domain_no_subname>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %rsi,%r15
mov    %rdi,%rbx
call   1080 <find_domain_no_www@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     124e <find_domain_no_subname+0xde>
lea    0xe65(%rip),%rsi
mov    %rsp,%rdx
mov    %r15,%rdi
call   1090 <split@plt>
mov    %eax,%r12d
movb   $0x0,(%r15)
mov    (%rsp),%rax
movslq %r12d,%rbp
mov    -0x8(%rax,%rbp,8),%rdi
call   1030 <isSecondLevelDomain@plt>
cmp    $0x1,%rax
mov    $0x3,%eax
sbb    $0x0,%eax
cmp    %eax,%r12d
jge    11e3 <find_domain_no_subname+0x73>
lea    0xe2c(%rip),%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1060 <printf@plt>
jmp    124e <find_domain_no_subname+0xde>
mov    %eax,%eax
lea    0x1(%rax),%rbx
shl    $0x3,%rbp
shl    $0x3,%rax
sub    %rax,%rbp
lea    0xe05(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rax
mov    (%rax,%rbp,1),%rsi
mov    %r15,%rdi
mov    %r13d,%edx
call   1040 <strlcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1040 <strlcat@plt>
add    $0xffffffffffffffff,%rbx
add    $0x8,%rbp
cmp    $0x1,%rbx
ja     1200 <find_domain_no_subname+0x90>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
mov    (%rsp),%rdi
call   1070 <FreeSplitList@plt>
mov    $0x1,%r14d
mov    %r14d,%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".\00"
@.str.1 = [29 x i8] c"bad domain url: \22%s\22, nr %i\0A\00"
define i32 @find_domain_no_subname(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = call i32 @find_domain_no_www(i8* %12, i8* %13, i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %3
store i32 0, i32* %4
br label %72
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = call i32 @split(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8*** %8)
store i32 %20, i32* %9
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 0, i8* %22
%23 = load i8**, i8*** %8
%24 = load i32, i32* %9
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %23, i64 %26
%28 = load i8*, i8** %27
%29 = call i64 @isSecondLevelDomain(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %18
store i32 3, i32* %11
br label %33
32: ; preds = %18
store i32 2, i32* %11
br label %33
33: ; preds = %32, %31
%34 = load i32, i32* %9
%35 = load i32, i32* %11
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i8*, i8** %5
%39 = load i32, i32* %9
%40 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 %39)
store i32 0, i32* %4
br label %72
41: ; preds = %33
%42 = load i32, i32* %11
store i32 %42, i32* %10
br label %43
43: ; preds = %60, %41
%44 = load i32, i32* %10
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %63
46: ; preds = %43
%47 = load i8*, i8** %6
%48 = load i8**, i8*** %8
%49 = load i32, i32* %9
%50 = load i32, i32* %10
%51 = sub nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %48, i64 %52
%54 = load i8*, i8** %53
%55 = load i32, i32* %7
%56 = call i32 @strlcat(i8* %47, i8* %54, i32 %55)
%57 = load i8*, i8** %6
%58 = load i32, i32* %7
%59 = call i32 @strlcat(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %46
%61 = load i32, i32* %10
%62 = add nsw i32 %61, -1
store i32 %62, i32* %10
br label %43
63: ; preds = %43
%64 = load i8*, i8** %6
%65 = load i8*, i8** %6
%66 = call i32 @strlen(i8* %65)
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %64, i64 %68
store i8 0, i8* %69
%70 = load i8**, i8*** %8
%71 = call i32 @FreeSplitList(i8** %70)
store i32 1, i32* %4
br label %72
72: ; preds = %63, %37, %17
%73 = load i32, i32* %4
ret i32 %73
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [29 x i8] c"bad domain url: \22%s\22, nr %i\0A\00"
define i32 @find_domain_no_subname(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = bitcast i8*** %4 to i8*
%6 = tail call i32 @find_domain_no_www(i8* %0, i8* %1, i32 %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %41, label %8
8: ; preds = %3
%9 = call i32 @split(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8*** %4)
store i8 0, i8* %1
%10 = load i8**, i8*** %4
%11 = add nsw i32 %9, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %10, i64 %12
%14 = load i8*, i8** %13
%15 = call i64 @isSecondLevelDomain(i8* %14)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i32 2, i32 3
%18 = icmp slt i32 %9, %17
br i1 %18, label %22, label %19
19: ; preds = %8
%20 = zext i32 %17 to i64
%21 = sext i32 %9 to i64
br label %24
22: ; preds = %8
%23 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %9)
br label %41
24: ; preds = %19, %24
%25 = phi i64 [ %20, %19 ], [ %32, %24 ]
%26 = load i8**, i8*** %4
%27 = sub nsw i64 %21, %25
%28 = getelementptr inbounds i8*, i8** %26, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @strlcat(i8* %1, i8* %29, i32 %2)
%31 = call i32 @strlcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %2)
%32 = add nsw i64 %25, -1
%33 = icmp ugt i64 %25, 1
br i1 %33, label %24, label %34
34: ; preds = %24
%35 = call i32 @strlen(i8* %1)
%36 = add nsw i32 %35, -1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %1, i64 %37
store i8 0, i8* %38
%39 = load i8**, i8*** %4
%40 = call i32 @FreeSplitList(i8** %39)
br label %41
41: ; preds = %3, %34, %22
%42 = phi i32 [ 0, %22 ], [ 1, %34 ], [ 0, %3 ]
ret i32 %42
}