#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*/ my_strcpy(char *, char *);
char *strdup(char *);
int main(void) {
  char *h = "hello, world";
  char *p1 = strdup(h);
  char *p2 = strdup(h);
  char u1[13];
  char u2[13];
  p1[p2 - p1] = 0;
  u1[p2 - u1] = 0;
  p1[u2 - p1] = 0;
  u1[u2 - u1] = 0;
  p1[p2 - p1 - 1] = 0;
  u1[p2 - u1 - 1] = 0;
  p1[u2 - p1 - 1] = 0;
  u1[u2 - u1 - 1] = 0;
  my_strcpy(u1, p1);
  my_strcpy(u2, u1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
lea    -0x2d(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x2d(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
lea    -0x3a(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x3a(%rbp),%rax
lea    -0x2d(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x2d(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
lea    -0x2d(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
movb   $0x0,-0x2d(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
lea    -0x3a(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x3a(%rbp),%rax
lea    -0x2d(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
movb   $0x0,-0x2d(%rbp,%rax,1)
lea    -0x2d(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <my_strcpy@plt>
lea    -0x3a(%rbp),%rdi
lea    -0x2d(%rbp),%rsi
call   1030 <my_strcpy@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xed2(%rip),%r14
mov    %r14,%rdi
call   1040 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strdup@plt>
movb   $0x0,(%rax)
movb   $0x0,0xe(%rsp)
movb   $0x0,-0x1(%rax)
movb   $0x0,0xd(%rsp)
lea    0x1b(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <my_strcpy@plt>
lea    0xe(%rsp),%rdi
mov    %r14,%rsi
call   1030 <my_strcpy@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"hello, world\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [13 x i8]
%6 = alloca [13 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @strdup(i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %2
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = load i8*, i8** %3
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = getelementptr inbounds i8, i8* %11, i64 %16
store i8 0, i8* %17
%18 = load i8*, i8** %4
%19 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 %22
store i8 0, i8* %23
%24 = load i8*, i8** %3
%25 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%26 = load i8*, i8** %3
%27 = ptrtoint i8* %25 to i64
%28 = ptrtoint i8* %26 to i64
%29 = sub i64 %27, %28
%30 = getelementptr inbounds i8, i8* %24, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%32 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %3
%38 = load i8*, i8** %4
%39 = load i8*, i8** %3
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = sub nsw i64 %42, 1
%44 = getelementptr inbounds i8, i8* %37, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %4
%46 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = sub nsw i64 %49, 1
%51 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 %50
store i8 0, i8* %51
%52 = load i8*, i8** %3
%53 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%54 = load i8*, i8** %3
%55 = ptrtoint i8* %53 to i64
%56 = ptrtoint i8* %54 to i64
%57 = sub i64 %55, %56
%58 = sub nsw i64 %57, 1
%59 = getelementptr inbounds i8, i8* %52, i64 %58
store i8 0, i8* %59
%60 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%61 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%62 = ptrtoint i8* %60 to i64
%63 = ptrtoint i8* %61 to i64
%64 = sub i64 %62, %63
%65 = sub nsw i64 %64, 1
%66 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 %65
store i8 0, i8* %66
%67 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%68 = load i8*, i8** %3
%69 = call i32 @my_strcpy(i8* %67, i8* %68)
%70 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%71 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%72 = call i32 @my_strcpy(i8* %70, i8* %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"hello, world\00"
define i32 @main() {
%1 = alloca [13 x i8]
%2 = alloca [13 x i8]
%3 = tail call dereferenceable_or_null(13) i8* @strdup(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = tail call dereferenceable_or_null(13) i8* @strdup(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %3 to i64
%9 = sub i64 %7, %8
%10 = getelementptr inbounds i8, i8* %3, i64 %9
store i8 0, i8* %10
%11 = ptrtoint [13 x i8]* %1 to i64
%12 = sub i64 %7, %11
%13 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %12
store i8 0, i8* %13
%14 = ptrtoint [13 x i8]* %2 to i64
%15 = sub i64 %14, %8
%16 = getelementptr inbounds i8, i8* %3, i64 %15
store i8 0, i8* %16
%17 = sub i64 %14, %11
%18 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
%19 = add nsw i64 %9, -1
%20 = getelementptr inbounds i8, i8* %3, i64 %19
store i8 0, i8* %20
%21 = add nsw i64 %12, -1
%22 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %21
store i8 0, i8* %22
%23 = add nsw i64 %15, -1
%24 = getelementptr inbounds i8, i8* %3, i64 %23
store i8 0, i8* %24
%25 = add nsw i64 %17, -1
%26 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %25
store i8 0, i8* %26
%27 = call i32 @my_strcpy(i8* %5, i8* %3)
%28 = call i32 @my_strcpy(i8* %6, i8* %5)
ret i32 0
}