#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__ strcmp(char *, char *);
int strlen(char *);
int is_valid_onion(char *onion_id) {
  char *prefix;
  if (onion_id == NULL) {
    return 0;
  }
  if (strlen(onion_id) != 22) {
    return 0;
  }
  prefix = strchr(onion_id, '.');
  if (prefix == NULL) {
    return 0;
  }
  if (strcmp(prefix, ".onion") != 0) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_valid_onion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <is_valid_onion+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <is_valid_onion+0x97>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x16,%eax
je     1171 <is_valid_onion+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <is_valid_onion+0x97>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119a <is_valid_onion+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <is_valid_onion+0x97>
mov    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11c0 <is_valid_onion+0x90>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <is_valid_onion+0x97>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_onion>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     1171 <is_valid_onion+0x41>
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x16,%eax
jne    1171 <is_valid_onion+0x41>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1171 <is_valid_onion+0x41>
lea    0xea0(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c".onion\00"
define i32 @is_valid_onion(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %25
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = icmp ne i32 %10, 22
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 0, i32* %2
br label %25
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i8* @strchr(i8* %14, i8 signext 46)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 0, i32* %2
br label %25
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %2
br label %25
24: ; preds = %19
store i32 1, i32* %2
br label %25
25: ; preds = %24, %23, %18, %12, %7
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [7 x i8] c".onion\00"
define i32 @is_valid_onion(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 22
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = tail call i8* @strchr(i8* %0, i8 signext 46)
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %9, %6, %3, %1
%14 = phi i32 [ 0, %1 ], [ 0, %3 ], [ 0, %6 ], [ %12, %9 ]
ret i32 %14
}