#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 *kmalloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *achar(char *str, char c) {
  int i = 0;
  char *ret = kmalloc(1024);
  int canCpy = 0;
  while (i < strlen(str)) {
    if (str[i] == c) {
      canCpy = 1;
    } else if (canCpy == 1) {
      strcat(ret, &str[i]);
    } else {
    }
    i++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<achar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x400,%edi
call   1050 <kmalloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11d9 <achar+0xa9>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    119e <achar+0x6e>
movl   $0x1,-0x1c(%rbp)
jmp    11cb <achar+0x9b>
cmpl   $0x1,-0x1c(%rbp)
jne    11c1 <achar+0x91>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
call   1040 <strcat@plt>
jmp    11c6 <achar+0x96>
jmp    11c6 <achar+0x96>
jmp    11cb <achar+0x9b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115e <achar+0x2e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<achar>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r12
mov    $0x400,%edi
call   1050 <kmalloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    119b <achar+0x6b>
xor    %ebp,%ebp
xor    %eax,%eax
jmp    1176 <achar+0x46>
nopl   (%rax)
add    $0x1,%rbp
mov    %r12,%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
mov    %ebx,%eax
cmp    %rcx,%rbp
jge    119b <achar+0x6b>
mov    $0x1,%ebx
cmp    %r15b,(%r12,%rbp,1)
je     1160 <achar+0x30>
xor    %ebx,%ebx
cmp    $0x1,%eax
jne    1160 <achar+0x30>
lea    (%r12,%rbp,1),%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
mov    $0x1,%ebx
jmp    1160 <achar+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @achar(i8* %0, i8 signext %1) {
%3 = tail call i8* @kmalloc(i32 1024)
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %22
6: ; preds = %2, %16
%7 = phi i64 [ %18, %16 ], [ 0, %2 ]
%8 = phi i32 [ %17, %16 ], [ 0, %2 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, %1
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = icmp eq i32 %8, 1
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @strcat(i8* %3, i8* %9)
br label %16
16: ; preds = %6, %14, %12
%17 = phi i32 [ 1, %14 ], [ 0, %12 ], [ 1, %6 ]
%18 = add nuw nsw i64 %7, 1
%19 = tail call i32 @strlen(i8* %0)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %6, label %22
22: ; preds = %16, %2
ret i8* %3
}