#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ bf_tlds(char *, char *);
int /*<<< orphan*/ check_valid_name(char *);
char *find_tldfile_path();
int /*<<< orphan*/ printf(char *, char *);
char *strrchr(char *, char);
int main(int argc, char **argv) {
  char *name, *ptr, *tldfile;
  if (argc < 2) {
    printf("Usage: %s <name>\n", argv[0]);
    return EXIT_FAILURE;
  }
  name = argv[1];
  ptr = strrchr(name, '.');
  if (ptr) {
    *ptr = 0;
    ptr = strrchr(name, '.');
    if (ptr)
      name = ++ptr;
  }
  if (!check_valid_name(name)) {
    printf("Invalid name `%s'\n", name);
    return EXIT_FAILURE;
  }
  tldfile = find_tldfile_path();
  if (!tldfile) {
    printf("Could not find TLD file: %s\n", "tlds-alpha-by-domain.txt");
    return EXIT_FAILURE;
  }
  bf_tlds(tldfile, name);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1194 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127c <main+0x12c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f6 <main+0xa6>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f1 <main+0xa1>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
jmp    11f6 <main+0xa6>
mov    -0x18(%rbp),%rdi
call   1060 <check_valid_name@plt>
cmp    $0x0,%eax
jne    1229 <main+0xd9>
mov    -0x18(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127c <main+0x12c>
mov    $0x0,%al
call   1030 <find_tldfile_path@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1263 <main+0x113>
lea    0xddf(%rip),%rdi
lea    0xdf5(%rip),%rsi
call   1040 <printf@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127c <main+0x12c>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <bf_tlds@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jg     1162 <main+0x12>
mov    (%rsi),%rsi
lea    0xea0(%rip),%rdi
jmp    11d9 <main+0x89>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1193 <main+0x43>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmovne %rcx,%rbx
mov    %rbx,%rdi
call   1060 <check_valid_name@plt>
test   %eax,%eax
je     11bf <main+0x6f>
xor    %eax,%eax
call   1030 <find_tldfile_path@plt>
test   %rax,%rax
je     11cb <main+0x7b>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1070 <bf_tlds@plt>
mov    0x2e1b(%rip),%rax
jmp    11e5 <main+0x95>
lea    0xe4c(%rip),%rdi
mov    %rbx,%rsi
jmp    11d9 <main+0x89>
lea    0xe53(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1040 <printf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s <name>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [19 x i8] c"Invalid name `%s'\0A\00"
@.str.2 = [29 x i8] c"Could not find TLD file: %s\0A\00"
@.str.3 = [25 x i8] c"tlds-alpha-by-domain.txt\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %55
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = call i8* @strrchr(i8* %21, i8 signext 46)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %35
25: ; preds = %17
%26 = load i8*, i8** %7
store i8 0, i8* %26
%27 = load i8*, i8** %6
%28 = call i8* @strrchr(i8* %27, i8 signext 46)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %7
store i8* %33, i8** %6
br label %34
34: ; preds = %31, %25
br label %35
35: ; preds = %34, %17
%36 = load i8*, i8** %6
%37 = call i32 @check_valid_name(i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
store i32 %42, i32* %3
br label %55
43: ; preds = %35
%44 = call i8* (...) @find_tldfile_path()
store i8* %44, i8** %8
%45 = load i8*, i8** %8
%46 = icmp ne i8* %45, null
br i1 %46, label %50, label %47
47: ; preds = %43
%48 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
store i32 %49, i32* %3
br label %55
50: ; preds = %43
%51 = load i8*, i8** %8
%52 = load i8*, i8** %6
%53 = call i32 @bf_tlds(i8* %51, i8* %52)
%54 = load i32, i32* @EXIT_SUCCESS
store i32 %54, i32* %3
br label %55
55: ; preds = %50, %47, %39, %11
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s <name>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [19 x i8] c"Invalid name `%s'\0A\00"
@.str.2 = [29 x i8] c"Could not find TLD file: %s\0A\00"
@.str.3 = [25 x i8] c"tlds-alpha-by-domain.txt\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %30
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %9, i8 signext 46)
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %7
store i8 0, i8* %10
%13 = tail call i8* @strrchr(i8* dereferenceable(1) %9, i8 signext 46)
%14 = icmp eq i8* %13, null
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = select i1 %14, i8* %9, i8* %15
br label %17
17: ; preds = %12, %7
%18 = phi i8* [ %9, %7 ], [ %16, %12 ]
%19 = tail call i32 @check_valid_name(i8* %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %30
23: ; preds = %17
%24 = tail call i8* (...) @find_tldfile_path()
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %30
28: ; preds = %23
%29 = tail call i32 @bf_tlds(i8* %24, i8* %18)
br label %30
30: ; preds = %28, %26, %21, %4
%31 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %28 ], [ @EXIT_FAILURE, %26 ], [ @EXIT_FAILURE, %21 ]
%32 = load i32, i32* %31
ret i32 %32
}