#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*/ assert(int);
char *mempcpy(char *, char *, int);
char *stpcpy(char *, char *);
char *stpncpy(char *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int main() {
  char test[100] = "blubber";
  assert(mempcpy(test, "foo", 3) == test + 3 && !strcmp(test, "foobber"));
  assert(mempcpy(test, "foo", 4) == test + 4 && !strcmp(test, "foo"));
  assert(stpcpy(test, "foo") == test + 3 && !strcmp(test, "foo"));
  stpncpy(test, "bar", 2);
  assert(stpncpy(test, "bar", 2) == test + 2 && !strcmp(test, "bao"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x64,%edx
call   1060 <memcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xed2(%rip),%rsi
mov    $0x3,%edx
call   1080 <mempcpy@plt>
mov    %rax,%rcx
lea    -0x70(%rbp),%rdx
add    $0x3,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x71(%rbp)
jne    11d0 <main+0x70>
lea    -0x70(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x70(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x4,%edx
call   1080 <mempcpy@plt>
mov    %rax,%rcx
lea    -0x70(%rbp),%rdx
add    $0x4,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x72(%rbp)
jne    1226 <main+0xc6>
lea    -0x70(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x72(%rbp)
mov    -0x72(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x70(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1030 <stpcpy@plt>
mov    %rax,%rcx
lea    -0x70(%rbp),%rdx
add    $0x3,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x73(%rbp)
jne    1277 <main+0x117>
lea    -0x70(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x73(%rbp)
mov    -0x73(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x70(%rbp),%rdi
lea    0xde1(%rip),%rsi
mov    $0x2,%edx
call   1070 <stpncpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xdcc(%rip),%rsi
mov    $0x2,%edx
call   1070 <stpncpy@plt>
mov    %rax,%rcx
lea    -0x70(%rbp),%rdx
add    $0x2,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x74(%rbp)
jne    12e2 <main+0x182>
lea    -0x70(%rbp),%rdi
lea    0xda2(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x74(%rbp)
mov    -0x74(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
movaps 0xf10(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xef4(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea0(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe84(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xed5(%rip),%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1050 <mempcpy@plt>
lea    0x3(%rsp),%rcx
movabs $0x726562626f6f66,%rdx
xor    (%rsp),%rdx
xor    %rax,%rcx
xor    %edi,%edi
or     %rcx,%rdx
sete   %dil
call   1030 <assert@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <mempcpy@plt>
lea    0x4(%rsp),%rcx
cmp    %rcx,%rax
sete   %al
cmpl   $0x6f6f66,(%rsp)
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
movl   $0x6f6f66,(%rsp)
mov    $0x1,%edi
call   1030 <assert@plt>
lea    0xe5b(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <stpncpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <stpncpy@plt>
lea    0x2(%rsp),%rcx
cmp    %rcx,%rax
sete   %al
cmpl   $0x6f6162,(%rsp)
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.test = [100 x i8] c"blubber\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [4 x i8] c"foo\00"
@.str.1 = [8 x i8] c"foobber\00"
@.str.2 = [4 x i8] c"bar\00"
@.str.3 = [4 x i8] c"bao\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
store i32 0, i32* %1
%3 = bitcast [100 x i8]* %2 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i8* @mempcpy(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds i8, i8* %6, i64 3
%8 = icmp eq i8* %5, %7
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br label %14
14: ; preds = %9, %0
%15 = phi i1 [ false, %0 ], [ %13, %9 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%19 = call i8* @mempcpy(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%21 = getelementptr inbounds i8, i8* %20, i64 4
%22 = icmp eq i8* %19, %21
br i1 %22, label %23, label %28
23: ; preds = %14
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br label %28
28: ; preds = %23, %14
%29 = phi i1 [ false, %14 ], [ %27, %23 ]
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%33 = call i8* @stpcpy(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%35 = getelementptr inbounds i8, i8* %34, i64 3
%36 = icmp eq i8* %33, %35
br i1 %36, label %37, label %42
37: ; preds = %28
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
br label %42
42: ; preds = %37, %28
%43 = phi i1 [ false, %28 ], [ %41, %37 ]
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%47 = call i8* @stpncpy(i8* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%49 = call i8* @stpncpy(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%51 = getelementptr inbounds i8, i8* %50, i64 2
%52 = icmp eq i8* %49, %51
br i1 %52, label %53, label %58
53: ; preds = %42
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
br label %58
58: ; preds = %53, %42
%59 = phi i1 [ false, %42 ], [ %57, %53 ]
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
ret i32 0
}

LLVM IR (-O2):
@__const.main.test = [100 x i8] c"blubber\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [4 x i8] c"foo\00"
@.str.2 = [4 x i8] c"bar\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i8* @mempcpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
%5 = icmp eq i8* %3, %4
%6 = bitcast [100 x i8]* %1 to i64*
%7 = load i64, i64* %6
%8 = icmp eq i64 %7, 32199620577685350
%9 = select i1 %5, i1 %8, i1 false
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = call i8* @mempcpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
%14 = icmp eq i8* %12, %13
%15 = bitcast [100 x i8]* %1 to i32*
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 7303014
%18 = select i1 %14, i1 %17, i1 false
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
store i32 7303014, i32* %15
%21 = call i32 @assert(i32 1)
%22 = call i8* @stpncpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%23 = call i8* @stpncpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%25 = icmp eq i8* %23, %24
%26 = load i32, i32* %15
%27 = icmp eq i32 %26, 7299426
%28 = select i1 %25, i1 %27, i1 false
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
ret i32 0
}