#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 */
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strscpy(char *, char const *, int);
int find_domain_no_www(const char url[], char domain[], int sizeofdomain) {
  char *cpnt;
  strscpy(domain, url + 7, sizeofdomain);
  if (strncmp(domain, "www.", 4) == 0) {
    strscpy(domain, domain + 4, sizeofdomain);
  }
  if ((cpnt = strchr(domain, '/')) == NULL) {
    return 0;
  } else {
    domain[cpnt - domain] = '\0';
    return 1;
  }
}


x86 assembly (clang, -O0):
<find_domain_no_www>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x7,%rsi
mov    -0x1c(%rbp),%edx
call   1050 <strscpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    118a <find_domain_no_www+0x5a>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
mov    -0x1c(%rbp),%edx
call   1050 <strscpy@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b2 <find_domain_no_www+0x82>
movl   $0x0,-0x4(%rbp)
jmp    11cc <find_domain_no_www+0x9c>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_domain_no_www>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
lea    0x7(%rdi),%rsi
mov    %rbx,%rdi
call   1050 <strscpy@plt>
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    116b <find_domain_no_www+0x3b>
lea    0x4(%rbx),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1050 <strscpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1187 <find_domain_no_www+0x57>
movb   $0x0,(%rax)
mov    $0x1,%eax
jmp    1189 <find_domain_no_www+0x59>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"www.\00"
define i32 @find_domain_no_www(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %6
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 7
%12 = load i32, i32* %7
%13 = call i32 @strscpy(i8* %9, i8* %11, i32 %12)
%14 = load i8*, i8** %6
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 4
%21 = load i32, i32* %7
%22 = call i32 @strscpy(i8* %18, i8* %20, i32 %21)
br label %23
23: ; preds = %17, %3
%24 = load i8*, i8** %6
%25 = call i8* @strchr(i8* %24, i8 signext 47)
store i8* %25, i8** %8
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 0, i32* %4
br label %36
28: ; preds = %23
%29 = load i8*, i8** %6
%30 = load i8*, i8** %8
%31 = load i8*, i8** %6
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = getelementptr inbounds i8, i8* %29, i64 %34
store i8 0, i8* %35
store i32 1, i32* %4
br label %36
36: ; preds = %28, %27
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
@.str = [5 x i8] c"www.\00"
define i32 @find_domain_no_www(i8* %0, i8* %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %0, i64 7
%5 = tail call i32 @strscpy(i8* %1, i8* %4, i32 %2)
%6 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %1, i64 4
%10 = tail call i32 @strscpy(i8* %1, i8* %9, i32 %2)
br label %11
11: ; preds = %8, %3
%12 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 47)
%13 = icmp eq i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = ptrtoint i8* %12 to i64
%16 = ptrtoint i8* %1 to i64
%17 = sub i64 %15, %16
%18 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %11, %14
%20 = phi i32 [ 1, %14 ], [ 0, %11 ]
ret i32 %20
}