#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*/ free(char *);
int match_host_and_ip(char const *, char const *, char *);
int match_pattern(char const *, char const *);
char *ssh_strdup(char const *);
char *strchr(char const *, char);
int match_user(const char *user, const char *host, const char *ipaddr,
               const char *pattern) {
  char *p, *pat;
  int ret;
  if ((p = strchr(pattern, '@')) == NULL)
    return match_pattern(user, pattern);
  pat = ssh_strdup(pattern);
  p = strchr(pat, '@');
  *p++ = '\0';
  if ((ret = match_pattern(user, pat)) == 1)
    ret = match_host_and_ip(host, ipaddr, p);
  free(pat);
  return ret;
}


x86 assembly (clang, -O0):
<match_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x40,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1199 <match_user+0x49>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <match_pattern@plt>
mov    %eax,-0x4(%rbp)
jmp    1206 <match_user+0xb6>
mov    -0x28(%rbp),%rdi
call   1060 <ssh_strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x40,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <match_pattern@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x1,%eax
jne    11f7 <match_user+0xa7>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <match_host_and_ip@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_user>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rcx,%rdi
mov    $0x40,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11d6 <match_user+0x86>
mov    %rbx,%rdi
call   1060 <ssh_strdup@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x40,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <match_pattern@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
jne    11bd <match_user+0x6d>
add    $0x1,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <match_host_and_ip@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <match_pattern@plt>

LLVM IR (-O0):
define i32 @match_user(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%13 = load i8*, i8** %9
%14 = call i8* @strchr(i8* %13, i8 signext 64)
store i8* %14, i8** %10
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = load i8*, i8** %9
%19 = call i32 @match_pattern(i8* %17, i8* %18)
store i32 %19, i32* %5
br label %40
20: ; preds = %4
%21 = load i8*, i8** %9
%22 = call i8* @ssh_strdup(i8* %21)
store i8* %22, i8** %11
%23 = load i8*, i8** %11
%24 = call i8* @strchr(i8* %23, i8 signext 64)
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %10
store i8 0, i8* %25
%27 = load i8*, i8** %6
%28 = load i8*, i8** %11
%29 = call i32 @match_pattern(i8* %27, i8* %28)
store i32 %29, i32* %12
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %36
31: ; preds = %20
%32 = load i8*, i8** %7
%33 = load i8*, i8** %8
%34 = load i8*, i8** %10
%35 = call i32 @match_host_and_ip(i8* %32, i8* %33, i8* %34)
store i32 %35, i32* %12
br label %36
36: ; preds = %31, %20
%37 = load i8*, i8** %11
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* %12
store i32 %39, i32* %5
br label %40
40: ; preds = %36, %16
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
define i32 @match_user(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i8* @strchr(i8* dereferenceable(1) %3, i8 signext 64)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @match_pattern(i8* %0, i8* %3)
br label %20
9: ; preds = %4
%10 = tail call i8* @ssh_strdup(i8* %3)
%11 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 64)
store i8 0, i8* %11
%12 = tail call i32 @match_pattern(i8* %0, i8* %10)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = tail call i32 @match_host_and_ip(i8* %1, i8* %2, i8* %15)
br label %17
17: ; preds = %14, %9
%18 = phi i32 [ %16, %14 ], [ %12, %9 ]
%19 = tail call i32 @free(i8* %10)
br label %20
20: ; preds = %17, %7
%21 = phi i32 [ %8, %7 ], [ %18, %17 ]
ret i32 %21
}