#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 */
void *ft_memccpy(void *dst, const void *src, int c, size_t n) {
  unsigned char *tail;
  char *srctail;
  tail = (unsigned char *)dst;
  srctail = (char *)src;
  while (n-- > 0) {
    *tail++ = *srctail++;
    if (*(tail - 1) == (unsigned char)c)
      return ((void *)tail);
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<ft_memccpy>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
cmp    $0x0,%rax
jbe    1186 <ft_memccpy+0x86>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x30(%rbp),%rax
movzbl -0x1(%rax),%eax
mov    -0x1c(%rbp),%ecx
movzbl %cl,%ecx
cmp    %ecx,%eax
jne    1181 <ft_memccpy+0x81>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118e <ft_memccpy+0x8e>
jmp    1123 <ft_memccpy+0x23>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_memccpy>:
xor    %eax,%eax
xor    %r8d,%r8d
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %r8,%rcx
je     112d <ft_memccpy+0x2d>
movzbl (%rsi,%r8,1),%r9d
mov    %r9b,(%rdi,%r8,1)
add    $0x1,%r8
cmp    %dl,%r9b
jne    1110 <ft_memccpy+0x10>
add    %r8,%rdi
mov    %rdi,%rax
ret

LLVM IR (-O0):
define i8* @ft_memccpy(i8* %0, i8* %1, i32 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64 %3, i64* %9
%12 = load i8*, i8** %6
store i8* %12, i8** %10
%13 = load i8*, i8** %7
store i8* %13, i8** %11
br label %14
14: ; preds = %34, %4
%15 = load i64, i64* %9
%16 = add i64 %15, -1
store i64 %16, i64* %9
%17 = icmp ugt i64 %15, 0
br i1 %17, label %18, label %35
18: ; preds = %14
%19 = load i8*, i8** %11
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %11
%21 = load i8, i8* %19
%22 = load i8*, i8** %10
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %10
store i8 %21, i8* %22
%24 = load i8*, i8** %10
%25 = getelementptr inbounds i8, i8* %24, i64 -1
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = load i32, i32* %8
%29 = trunc i32 %28 to i8
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %27, %30
br i1 %31, label %32, label %34
32: ; preds = %18
%33 = load i8*, i8** %10
store i8* %33, i8** %5
br label %36
34: ; preds = %18
br label %14
35: ; preds = %14
store i8* null, i8** %5
br label %36
36: ; preds = %35, %32
%37 = load i8*, i8** %5
ret i8* %37
}

LLVM IR (-O2):
define i8* @ft_memccpy(i8* writeonly %0, i8* nocapture %1, i32 %2, i64 %3) {
%5 = trunc i32 %2 to i8
br label %6
6: ; preds = %11, %4
%7 = phi i64 [ %3, %4 ], [ %12, %11 ]
%8 = phi i8* [ %0, %4 ], [ %15, %11 ]
%9 = phi i8* [ %1, %4 ], [ %13, %11 ]
%10 = icmp eq i64 %7, 0
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = add i64 %7, -1
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %9
%15 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %14, i8* %8
%16 = icmp eq i8 %14, %5
br i1 %16, label %17, label %6
17: ; preds = %6, %11
%18 = phi i8* [ %15, %11 ], [ null, %6 ]
ret i8* %18
}