#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(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_domains_subname(const char url[], char domain[], int sizeofdomain) {
  char **Data;
  int TokCount;
  int i;
  int nrToGet;
  if (!find_domain(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 = 0; i < (TokCount - nrToGet); i++) {
    strlcat(domain, Data[i], sizeofdomain);
    strlcat(domain, ".", sizeofdomain);
  }
  domain[strlen(domain) - 1] = '\0';
  FreeSplitList(Data);
  return 1;
}


x86 assembly (clang, -O0):
<find_domains_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   1090 <find_domain@plt>
cmp    $0x0,%eax
jne    11a8 <find_domains_subname+0x38>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <find_domains_subname+0x136>
mov    -0x18(%rbp),%rdi
lea    0xe4d(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1080 <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_domains_subname+0x82>
movl   $0x3,-0x34(%rbp)
jmp    11f9 <find_domains_subname+0x89>
movl   $0x2,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1224 <find_domains_subname+0xb4>
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xdef(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <find_domains_subname+0x136>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    -0x34(%rbp),%ecx
cmp    %ecx,%eax
jge    1275 <find_domains_subname+0x105>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strlcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd9e(%rip),%rsi
call   1040 <strlcat@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    122b <find_domains_subname+0xbb>
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_domains_subname>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %rsi,%rbx
mov    %rdi,%r15
call   1090 <find_domain@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     1248 <find_domains_subname+0xd8>
lea    0xe65(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1080 <split@plt>
mov    %eax,%r12d
movb   $0x0,(%rbx)
mov    (%rsp),%rax
movslq %r12d,%rcx
mov    -0x8(%rax,%rcx,8),%rdi
call   1030 <isSecondLevelDomain@plt>
cmp    $0x1,%rax
mov    $0x3,%ecx
sbb    $0x0,%ecx
mov    %r12d,%eax
sub    %ecx,%eax
jge    11e4 <find_domains_subname+0x74>
lea    0xe2b(%rip),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1060 <printf@plt>
jmp    1248 <find_domains_subname+0xd8>
test   %eax,%eax
jle    122a <find_domains_subname+0xba>
mov    %eax,%r15d
xor    %ebp,%ebp
lea    0xe0c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%rax
mov    (%rax,%rbp,8),%rsi
mov    %rbx,%rdi
mov    %r13d,%edx
call   1040 <strlcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1040 <strlcat@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1200 <find_domains_subname+0x90>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,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_domains_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(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
store i32 0, i32* %10
br label %42
42: ; preds = %60, %41
%43 = load i32, i32* %10
%44 = load i32, i32* %9
%45 = load i32, i32* %11
%46 = sub nsw i32 %44, %45
%47 = icmp slt i32 %43, %46
br i1 %47, label %48, label %63
48: ; preds = %42
%49 = load i8*, i8** %6
%50 = load i8**, i8*** %8
%51 = load i32, i32* %10
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = load i32, i32* %7
%56 = call i32 @strlcat(i8* %49, 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 = %48
%61 = load i32, i32* %10
%62 = add nsw i32 %61, 1
store i32 %62, i32* %10
br label %42
63: ; preds = %42
%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_domains_subname(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = bitcast i8*** %4 to i8*
%6 = tail call i32 @find_domain(i8* %0, i8* %1, i32 %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %42, 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 %24, label %19
19: ; preds = %8
%20 = sub i32 %9, %17
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = zext i32 %20 to i64
br label %26
24: ; preds = %8
%25 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %9)
br label %42
26: ; preds = %22, %26
%27 = phi i64 [ 0, %22 ], [ %33, %26 ]
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 %27
%30 = load i8*, i8** %29
%31 = call i32 @strlcat(i8* %1, i8* %30, i32 %2)
%32 = call i32 @strlcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %2)
%33 = add nuw nsw i64 %27, 1
%34 = icmp eq i64 %33, %23
br i1 %34, label %35, label %26
35: ; preds = %26, %19
%36 = call i32 @strlen(i8* %1)
%37 = add nsw i32 %36, -1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %1, i64 %38
store i8 0, i8* %39
%40 = load i8**, i8*** %4
%41 = call i32 @FreeSplitList(i8** %40)
br label %42
42: ; preds = %3, %35, %24
%43 = phi i32 [ 0, %24 ], [ 1, %35 ], [ 0, %3 ]
ret i32 %43
}