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

/* Variables and functions */
int /*<<< orphan*/ debug(char *, char *);
int /*<<< orphan*/ find_domains_subname(char *, char *, int);
int strchrcount(char *, char);
int url_nrOfSubDomains(char url[]) {
  int subdomains;
  char domain[512];
  if (!find_domains_subname(url, domain, sizeof(domain))) {
    debug("gyldig_url: can't find domain. Url \"%s\"\n", url);
    return -1;
  }
  if (domain[0] == '\0') {
    return 0;
  }
  subdomains = strchrcount(domain, '.');
  ++subdomains;
  return subdomains;
}


x86 assembly (clang, -O0):
<url_nrOfSubDomains>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1050 <find_domains_subname@plt>
cmp    $0x0,%eax
jne    1179 <url_nrOfSubDomains+0x49>
mov    -0x10(%rbp),%rsi
lea    0xe98(%rip),%rdi
call   1030 <debug@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <url_nrOfSubDomains+0x88>
movsbl -0x220(%rbp),%eax
cmp    $0x0,%eax
jne    1195 <url_nrOfSubDomains+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <url_nrOfSubDomains+0x88>
lea    -0x220(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchrcount@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_nrOfSubDomains>:
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0x200,%edx
call   1050 <find_domains_subname@plt>
test   %eax,%eax
je     1164 <url_nrOfSubDomains+0x34>
cmpb   $0x0,(%rsp)
je     117a <url_nrOfSubDomains+0x4a>
mov    %rsp,%rdi
mov    $0x2e,%esi
call   1040 <strchrcount@plt>
add    $0x1,%eax
jmp    117c <url_nrOfSubDomains+0x4c>
lea    0xe95(%rip),%rdi
mov    %rbx,%rsi
call   1030 <debug@plt>
mov    $0xffffffff,%eax
jmp    117c <url_nrOfSubDomains+0x4c>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"gyldig_url: can't find domain. Url \22%s\22\0A\00"
define i32 @url_nrOfSubDomains(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [512 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = call i32 @find_domains_subname(i8* %6, i8* %7, i32 512)
%9 = icmp ne i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @debug(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 -1, i32* %2
br label %25
13: ; preds = %1
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 0, i32* %2
br label %25
19: ; preds = %13
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%21 = call i32 @strchrcount(i8* %20, i8 signext 46)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %25
25: ; preds = %19, %18, %10
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [41 x i8] c"gyldig_url: can't find domain. Url \22%s\22\0A\00"
define i32 @url_nrOfSubDomains(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @find_domains_subname(i8* %0, i8* %3, i32 512)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @debug(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
8: ; preds = %1
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = call i32 @strchrcount(i8* %3, i8 signext 46)
%13 = add nsw i32 %12, 1
br label %14
14: ; preds = %8, %11, %6
%15 = phi i32 [ %13, %11 ], [ -1, %6 ], [ 0, %8 ]
ret i32 %15
}