#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*/ enough_mem(char *);
char *extract_userhost(char const *);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
char *strrchr(char *, char);
char *extract_hostname(const char *s) {
  const char *p;
  char *t = extract_userhost(s);
  char *r;
  if (!t) {
    return (char *)0;
  }
  p = strrchr(t, '@');
  if (!p) {
    return (char *)0;
  }
  p++;
  r = strdup(p);
  enough_mem(r);
  free(t);
  return r;
}


x86 assembly (clang, -O0):
<extract_hostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <extract_userhost@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1181 <extract_hostname+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11de <extract_hostname+0x8e>
mov    -0x20(%rbp),%rdi
mov    $0x40,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <extract_hostname+0x5b>
movq   $0x0,-0x8(%rbp)
jmp    11de <extract_hostname+0x8e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <enough_mem@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_hostname>:
push   %r14
push   %rbx
push   %rax
call   1060 <extract_userhost@plt>
test   %rax,%rax
je     1194 <extract_hostname+0x44>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x40,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1194 <extract_hostname+0x44>
add    $0x1,%rax
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <enough_mem@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1197 <extract_hostname+0x47>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @extract_hostname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @extract_userhost(i8* %7)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i8* null, i8** %2
br label %28
12: ; preds = %1
%13 = load i8*, i8** %5
%14 = call i8* @strrchr(i8* %13, i8 signext 64)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %12
store i8* null, i8** %2
br label %28
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i8* @strdup(i8* %21)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @enough_mem(i8* %23)
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %6
store i8* %27, i8** %2
br label %28
28: ; preds = %18, %17, %11
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
define i8* @extract_hostname(i8* %0) {
%2 = tail call i8* @extract_userhost(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i8* @strrchr(i8* %2, i8 signext 64)
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = tail call i8* @strdup(i8* %8)
%10 = tail call i32 @enough_mem(i8* %9)
%11 = tail call i32 @free(i8* %2)
br label %12
12: ; preds = %4, %1, %7
%13 = phi i8* [ %9, %7 ], [ null, %1 ], [ null, %4 ]
ret i8* %13
}