#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 *s1, const void *s2, int c, size_t n) {
  unsigned char *src_as_uc;
  src_as_uc = (unsigned char *)s2;
  while (n-- != 0) {
    if (*src_as_uc == (unsigned char)c) {
      *(unsigned char *)s1++ = *src_as_uc;
      return (s1);
    } else
      *(unsigned char *)s1++ = *src_as_uc++;
  }
  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    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
cmp    $0x0,%rax
je     1194 <ft_memccpy+0x94>
mov    -0x30(%rbp),%rax
movzbl (%rax),%eax
mov    -0x1c(%rbp),%ecx
movzbl %cl,%ecx
cmp    %ecx,%eax
jne    116d <ft_memccpy+0x6d>
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119c <ft_memccpy+0x9c>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    111b <ft_memccpy+0x1b>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_memccpy>:
test   %rcx,%rcx
je     1145 <ft_memccpy+0x45>
mov    %rdi,%rax
neg    %rcx
add    $0x1,%rax
mov    $0x1,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%rsi,%rdi,1),%r8d
cmp    %dl,%r8b
je     1148 <ft_memccpy+0x48>
mov    %r8b,-0x1(%rax)
lea    (%rcx,%rdi,1),%r8
add    $0x1,%r8
add    $0x1,%rdi
add    $0x1,%rax
cmp    $0x1,%r8
jne    1120 <ft_memccpy+0x20>
xor    %eax,%eax
ret
mov    %dl,-0x1(%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*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64 %3, i64* %9
%11 = load i8*, i8** %7
store i8* %11, i8** %10
br label %12
12: ; preds = %36, %4
%13 = load i64, i64* %9
%14 = add i64 %13, -1
store i64 %14, i64* %9
%15 = icmp ne i64 %13, 0
br i1 %15, label %16, label %37
16: ; preds = %12
%17 = load i8*, i8** %10
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = load i32, i32* %8
%21 = trunc i32 %20 to i8
%22 = zext i8 %21 to i32
%23 = icmp eq i32 %19, %22
br i1 %23, label %24, label %30
24: ; preds = %16
%25 = load i8*, i8** %10
%26 = load i8, i8* %25
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
store i8 %26, i8* %27
%29 = load i8*, i8** %6
store i8* %29, i8** %5
br label %38
30: ; preds = %16
%31 = load i8*, i8** %10
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %10
%33 = load i8, i8* %31
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %6
store i8 %33, i8* %34
br label %36
36: ; preds = %30
br label %12
37: ; preds = %12
store i8* null, i8** %5
br label %38
38: ; preds = %37, %24
%39 = load i8*, i8** %5
ret i8* %39
}

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