#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*/ printf(char *);
char *strrchr(char *, char);
int /*<<< orphan*/ strscpy(char *, char *, int);
int find_TLD(char domain[], char TLD[], int TLDsize) {
  char *cpoint;
  if ((cpoint = strrchr(domain, '.')) == NULL) {
    printf("bad domain\n");
    return 0;
  }
  ++cpoint;
  strscpy(TLD, cpoint, TLDsize);
  return 1;
}


x86 assembly (clang, -O0):
<find_TLD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1177 <find_TLD+0x47>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    119a <find_TLD+0x6a>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <strscpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_TLD>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     115f <find_TLD+0x2f>
add    $0x1,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1050 <strscpy@plt>
mov    $0x1,%eax
jmp    116d <find_TLD+0x3d>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"bad domain\0A\00"
define i32 @find_TLD(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** %5
%10 = call i8* @strrchr(i8* %9, i8 signext 46)
store i8* %10, i8** %8
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %21
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %8
%17 = load i8*, i8** %6
%18 = load i8*, i8** %8
%19 = load i32, i32* %7
%20 = call i32 @strscpy(i8* %17, i8* %18, i32 %19)
store i32 1, i32* %4
br label %21
21: ; preds = %14, %12
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
@str = [11 x i8] c"bad domain\00"
define i32 @find_TLD(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %11
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %4, i64 1
%10 = tail call i32 @strscpy(i8* %1, i8* %9, i32 %2)
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ 0, %6 ], [ 1, %8 ]
ret i32 %12
}