#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*/ strcpy(char *, char *);
char *trim_until_character(char *destination, char c, char *source,
                           int num2trim) {
  char *anchor = source;
  *destination = '\0';
  if (num2trim <= 0)
    num2trim = 1;
  while (*source) {
    if (*source == c) {
      if (--num2trim == 0) {
        strcpy(destination, source + 1);
        return destination;
      }
    }
    source++;
  }
  return anchor;
}


x86 assembly (clang, -O0):
<trim_until_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x24(%rbp)
jg     1149 <trim_until_character+0x39>
movl   $0x1,-0x24(%rbp)
jmp    114e <trim_until_character+0x3e>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b4 <trim_until_character+0xa4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    11a3 <trim_until_character+0x93>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    119e <trim_until_character+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <trim_until_character+0xac>
jmp    11a3 <trim_until_character+0x93>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114e <trim_until_character+0x3e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_until_character>:
push   %r14
push   %rbx
push   %rax
movb   $0x0,(%rdi)
mov    (%rdx),%bl
test   %bl,%bl
je     1152 <trim_until_character+0x42>
mov    %rdi,%r14
test   %ecx,%ecx
mov    $0x1,%edi
cmovg  %ecx,%edi
lea    0x1(%rdx),%rax
jmp    113b <trim_until_character+0x2b>
movzbl (%rax),%ebx
add    $0x1,%rax
test   %bl,%bl
je     1152 <trim_until_character+0x42>
cmp    %sil,%bl
jne    1130 <trim_until_character+0x20>
add    $0xffffffff,%edi
jne    1130 <trim_until_character+0x20>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
jmp    1155 <trim_until_character+0x45>
mov    %rdx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @trim_until_character(i8* %0, i8 signext %1, i8* %2, i32 %3) {
store i8 0, i8* %0
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %26, label %7
7: ; preds = %4
%8 = icmp sgt i32 %3, 1
%9 = select i1 %8, i32 %3, i32 1
br label %10
10: ; preds = %7, %21
%11 = phi i8 [ %24, %21 ], [ %5, %7 ]
%12 = phi i32 [ %22, %21 ], [ %9, %7 ]
%13 = phi i8* [ %23, %21 ], [ %2, %7 ]
%14 = icmp eq i8 %11, %1
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = add nsw i32 %12, -1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %13, i64 1
%20 = tail call i32 @strcpy(i8* %0, i8* %19)
br label %26
21: ; preds = %15, %10
%22 = phi i32 [ %16, %15 ], [ %12, %10 ]
%23 = getelementptr inbounds i8, i8* %13, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %10
26: ; preds = %21, %4, %18
%27 = phi i8* [ %0, %18 ], [ %2, %4 ], [ %2, %21 ]
ret i8* %27
}