#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 const *, char);
char const *last_plain_colon(char const *p) {
  char const *found = NULL;
  char const *next = strchr(p, ':');
  while (next && next[1] != '\\') {
    found = next;
    next = strchr(next + 1, ':');
  }
  return found;
}


x86 assembly (clang, -O0):
<last_plain_colon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     1157 <last_plain_colon+0x47>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x5c,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1167 <last_plain_colon+0x57>
jmp    118a <last_plain_colon+0x7a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
jmp    1136 <last_plain_colon+0x26>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_plain_colon>:
push   %rbx
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1126 <last_plain_colon+0x16>
cmpb   $0x5c,0x1(%rax)
jne    112d <last_plain_colon+0x1d>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret
mov    %rax,%rdi
add    $0x1,%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%rbx
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1128 <last_plain_colon+0x18>
mov    %rax,%rdi
add    $0x1,%rdi
cmpb   $0x5c,0x1(%rax)
jne    1140 <last_plain_colon+0x30>
jmp    1128 <last_plain_colon+0x18>

LLVM IR (-O0):
define i8* @last_plain_colon(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 58)
store i8* %6, i8** %4
br label %7
7: ; preds = %18, %1
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 92
br label %16
16: ; preds = %10, %7
%17 = phi i1 [ false, %7 ], [ %15, %10 ]
br i1 %17, label %18, label %23
18: ; preds = %16
%19 = load i8*, i8** %4
store i8* %19, i8** %3
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i8* @strchr(i8* %21, i8 signext 58)
store i8* %22, i8** %4
br label %7
23: ; preds = %16
%24 = load i8*, i8** %3
ret i8* %24
}

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