#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 */
scalar_t__ malloc(unsigned long);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *bchar(char *a, char b) {
  for (int i = 0; i < strlen(a) - 1; i++) {
    if (a[i] == b) {
      unsigned long l = strlen(a) - i;
      char *cpy = (char *)malloc(l);
      strcpy(cpy, a + i + 1);
      return cpy;
    }
  }
}


x86 assembly (clang, -O0):
<bchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d7 <bchar+0xa7>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    11c4 <bchar+0x94>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    -0x18(%rbp),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <bchar+0xa7>
jmp    11c9 <bchar+0x99>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1149 <bchar+0x19>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bchar>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     1194 <bchar+0x64>
xor    %ebp,%ebp
nopl   0x0(%rax)
cmp    %r15b,(%rbx,%rbp,1)
je     116e <bchar+0x3e>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbp
jl     1150 <bchar+0x20>
jmp    1194 <bchar+0x64>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
sub    %rbp,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    (%rbx,%rbp,1),%rsi
add    $0x1,%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @bchar(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i8 %1, i8* %5
store i32 0, i32* %6
br label %9
9: ; preds = %43, %2
%10 = load i32, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = icmp slt i32 %10, %13
br i1 %14, label %15, label %46
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %21, %23
br i1 %24, label %25, label %42
25: ; preds = %15
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = load i32, i32* %6
%29 = sub nsw i32 %27, %28
%30 = sext i32 %29 to i64
store i64 %30, i64* %7
%31 = load i64, i64* %7
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 @strcpy(i8* %34, i8* %39)
%41 = load i8*, i8** %8
store i8* %41, i8** %3
br label %46
42: ; preds = %15
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %9
46: ; preds = %25, %9
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
define i8* @bchar(i8* %0, i8 signext %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 1
br i1 %4, label %5, label %27
5: ; preds = %2, %21
%6 = phi i64 [ %22, %21 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, %1
br i1 %9, label %10, label %21
10: ; preds = %5
%11 = trunc i64 %6 to i32
%12 = and i64 %6, 4294967295
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i32 @strlen(i8* %0)
%15 = sub nsw i32 %14, %11
%16 = sext i32 %15 to i64
%17 = tail call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = getelementptr inbounds i8, i8* %13, i64 1
%20 = tail call i32 @strcpy(i8* %18, i8* %19)
br label %27
21: ; preds = %5
%22 = add nuw nsw i64 %6, 1
%23 = tail call i32 @strlen(i8* %0)
%24 = add nsw i32 %23, -1
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %22, %25
br i1 %26, label %5, label %27
27: ; preds = %21, %2, %10
%28 = phi i8* [ %18, %10 ], [ undef, %2 ], [ undef, %21 ]
ret i8* %28
}