#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 strcasecmp(char const *, char const *);
int strncasecmp(char const *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ strpos(char const *, char);
int stracmp_host(const char *s1, const char *s2) {
  int ret;
  ret = strcasecmp(s1, s2);
  if (ret == 0)
    return 0;
  ret = strncasecmp(s1, s2, strpos(s1, '.'));
  if (ret == 0)
    return 2;
  ret = strncasecmp(s1, s2, strpos(s2, '.'));
  if (ret == 0)
    return 2;
  return 1;
}


x86 assembly (clang, -O0):
<stracmp_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1166 <stracmp_host+0x36>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <stracmp_host+0xc9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strpos@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11ac <stracmp_host+0x7c>
movl   $0x2,-0x4(%rbp)
jmp    11f9 <stracmp_host+0xc9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strpos@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11f2 <stracmp_host+0xc2>
movl   $0x2,-0x4(%rbp)
jmp    11f9 <stracmp_host+0xc9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stracmp_host>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1188 <stracmp_host+0x58>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strpos@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
je     118c <stracmp_host+0x5c>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1050 <strpos@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
cmp    $0x1,%eax
mov    $0x1,%eax
adc    $0x0,%eax
jmp    1191 <stracmp_host+0x61>
xor    %eax,%eax
jmp    1191 <stracmp_host+0x61>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @stracmp_host(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i8*, i8** %5
%9 = call i32 @strcasecmp(i8* %7, i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %32
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = load i8*, i8** %4
%17 = call i32 @strpos(i8* %16, i8 signext 46)
%18 = call i32 @strncasecmp(i8* %14, i8* %15, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 2, i32* %3
br label %32
22: ; preds = %13
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = load i8*, i8** %5
%26 = call i32 @strpos(i8* %25, i8 signext 46)
%27 = call i32 @strncasecmp(i8* %23, i8* %24, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %22
store i32 2, i32* %3
br label %32
31: ; preds = %22
store i32 1, i32* %3
br label %32
32: ; preds = %31, %30, %21, %12
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @stracmp_host(i8* %0, i8* %1) {
%3 = tail call i32 @strcasecmp(i8* %0, i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i32 @strpos(i8* %0, i8 signext 46)
%7 = tail call i32 @strncasecmp(i8* %0, i8* %1, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = tail call i32 @strpos(i8* %1, i8 signext 46)
%11 = tail call i32 @strncasecmp(i8* %0, i8* %1, i32 %10)
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 2, i32 1
br label %14
14: ; preds = %9, %5, %2
%15 = phi i32 [ 0, %2 ], [ 2, %5 ], [ %13, %9 ]
ret i32 %15
}