#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 *memcpy(char *, void const *, int);
int /*<<< orphan*/ sink(char *);
void warn_memcpy_chain(const void *s) {
  extern char cpy_a8[8];
  char *p = cpy_a8;
  p = memcpy(p, s, 9);
  sink(p);
  p = memcpy(p + 2, s, 7);
  sink(p);
  p = memcpy(p + 3, s, 5);
  sink(p);
  p = memcpy(p + 3, s, 3);
  sink(p);
}


x86 assembly (clang, -O0):
<warn_memcpy_chain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2eb5(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x9,%edx
call   1030 <memcpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sink@plt>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    -0x8(%rbp),%rsi
mov    $0x7,%edx
call   1030 <memcpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sink@plt>
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
mov    -0x8(%rbp),%rsi
mov    $0x5,%edx
call   1030 <memcpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sink@plt>
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3,%edx
call   1030 <memcpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sink@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<warn_memcpy_chain>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eba(%rip),%rdi
mov    %r14,%rsi
mov    $0x9,%edx
call   1030 <memcpy@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <sink@plt>
add    $0x2,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <memcpy@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <sink@plt>
add    $0x3,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <memcpy@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <sink@plt>
add    $0x3,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <memcpy@plt>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <sink@plt>

LLVM IR (-O0):
@cpy_a8 = external global [8 x i8]
define void @warn_memcpy_chain(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @cpy_a8, i64 0, i64 0), i8** %3
%4 = load i8*, i8** %3
%5 = load i8*, i8** %2
%6 = call i8* @memcpy(i8* %4, i8* %5, i32 9)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @sink(i8* %7)
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 2
%11 = load i8*, i8** %2
%12 = call i8* @memcpy(i8* %10, i8* %11, i32 7)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = call i32 @sink(i8* %13)
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 3
%17 = load i8*, i8** %2
%18 = call i8* @memcpy(i8* %16, i8* %17, i32 5)
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = call i32 @sink(i8* %19)
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 3
%23 = load i8*, i8** %2
%24 = call i8* @memcpy(i8* %22, i8* %23, i32 3)
store i8* %24, i8** %3
%25 = load i8*, i8** %3
%26 = call i32 @sink(i8* %25)
ret void
}

LLVM IR (-O2):
@cpy_a8 = external global [8 x i8]
define void @warn_memcpy_chain(i8* %0) {
%2 = tail call i8* @memcpy(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @cpy_a8, i64 0, i64 0), i8* %0, i32 9)
%3 = tail call i32 @sink(i8* %2)
%4 = getelementptr inbounds i8, i8* %2, i64 2
%5 = tail call i8* @memcpy(i8* %4, i8* %0, i32 7)
%6 = tail call i32 @sink(i8* %5)
%7 = getelementptr inbounds i8, i8* %5, i64 3
%8 = tail call i8* @memcpy(i8* %7, i8* %0, i32 5)
%9 = tail call i32 @sink(i8* %8)
%10 = getelementptr inbounds i8, i8* %8, i64 3
%11 = tail call i8* @memcpy(i8* %10, i8* %0, i32 3)
%12 = tail call i32 @sink(i8* %11)
ret void
}