#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 *strrchr(char *, char);
char *qname_open(char **surip, char **snamep, char *name) {
  char *sep;
  if ((sep = strrchr(name, ':'))) {
    *snamep = sep + 1;
    *surip = name;
    *sep = '\0';
  } else {
    *snamep = name;
    while (*name)
      ++name;
    *surip = name;
  }
  return sep;
}


x86 assembly (clang, -O0):
<qname_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1166 <qname_open+0x56>
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    119a <qname_open+0x8a>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     118f <qname_open+0x7f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1171 <qname_open+0x61>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qname_open>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdx,%rdi
mov    $0x3a,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1142 <qname_open+0x32>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,(%r15)
mov    %rbx,(%r14)
movb   $0x0,(%rax)
jmp    115d <qname_open+0x4d>
mov    %rbx,(%r15)
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1150 <qname_open+0x40>
mov    %rbx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @qname_open(i8** nocapture writeonly %0, i8** nocapture writeonly %1, i8* %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
store i8* %7, i8** %1
store i8* %2, i8** %0
store i8 0, i8* %4
br label %15
8: ; preds = %3
store i8* %2, i8** %1
br label %9
9: ; preds = %9, %8
%10 = phi i8* [ %2, %8 ], [ %13, %9 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = getelementptr inbounds i8, i8* %10, i64 1
br i1 %12, label %14, label %9
14: ; preds = %9
store i8* %10, i8** %0
br label %15
15: ; preds = %14, %6
ret i8* %4
}