#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__ memccpy(void *, void const *, int, size_t);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char const *);
void memccpyTest() {
  const char *src = "This is the sourc";
  char dest[50];
  char *ptr;
  ptr = (char *)(memccpy((void *)dest, (const void *)src, (int)'c',
                         (size_t)(strlen(src) - 1)));
  if (ptr) {
    *ptr = '\0';
    printf("The character was found: %s\n", dest);
  } else {
    printf("The character wasn't found\n");
  }
}


x86 assembly (clang, -O0):
<memccpyTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xec1(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
sub    $0x1,%eax
movslq %eax,%rcx
mov    $0x63,%edx
call   1050 <memccpy@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     11a1 <memccpyTest+0x71>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x40(%rbp),%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11af <memccpyTest+0x7f>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memccpyTest>:
push   %rbx
sub    $0x40,%rsp
lea    0xeb4(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0xffffffff,%eax
movslq %eax,%rcx
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x63,%edx
call   1060 <memccpy@plt>
test   %rax,%rax
je     1185 <memccpyTest+0x45>
movb   $0x0,(%rax)
lea    0xe99(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1191 <memccpyTest+0x51>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"This is the sourc\00"
@.str.1 = [29 x i8] c"The character was found: %s\0A\00"
@.str.2 = [28 x i8] c"The character wasn't found\0A\00"
define void @memccpyTest() {
%1 = alloca i8*
%2 = alloca [50 x i8]
%3 = alloca i8*
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %1
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = load i8*, i8** %1
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = call i64 @memccpy(i8* %4, i8* %5, i32 99, i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i8*, i8** %3
store i8 0, i8* %15
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"This is the sourc\00"
@.str.1 = [29 x i8] c"The character was found: %s\0A\00"
@str = [27 x i8] c"The character wasn't found\00"
define void @memccpyTest() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = call i64 @memccpy(i8* %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 99, i64 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = inttoptr i64 %6 to i8*
store i8 0, i8* %9
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
ret void
}