#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);
int /*<<< orphan*/ memcmp(char *, char *, 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"));
  assert(stpncpy(test, "xyz", 6) == test + 3 && !memcmp(test, "xyz\0\0\0", 6));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe73(%rip),%rsi
mov    $0x64,%edx
call   1070 <memcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xec9(%rip),%rsi
mov    $0x3,%edx
call   1090 <mempcpy@plt>
mov    %rax,%rcx
lea    -0x70(%rbp),%rdx
add    $0x3,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x71(%rbp)
jne    11e0 <main+0x70>
lea    -0x70(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1050 <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   1060 <assert@plt>
lea    -0x70(%rbp),%rdi
lea    0xe73(%rip),%rsi
mov    $0x4,%edx
call   1090 <mempcpy@plt>
mov    %rax,%rcx
lea    -0x70(%rbp),%rdx
add    $0x4,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x72(%rbp)
jne    1236 <main+0xc6>
lea    -0x70(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1050 <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   1060 <assert@plt>
lea    -0x70(%rbp),%rdi
lea    0xe1d(%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    1287 <main+0x117>
lea    -0x70(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1050 <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   1060 <assert@plt>
lea    -0x70(%rbp),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x2,%edx
call   1080 <stpncpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xdc3(%rip),%rsi
mov    $0x2,%edx
call   1080 <stpncpy@plt>
mov    %rax,%rcx
lea    -0x70(%rbp),%rdx
add    $0x2,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x74(%rbp)
jne    12f2 <main+0x182>
lea    -0x70(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1050 <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   1060 <assert@plt>
lea    -0x70(%rbp),%rdi
lea    0xd75(%rip),%rsi
mov    $0x6,%edx
call   1080 <stpncpy@plt>
mov    %rax,%rcx
lea    -0x70(%rbp),%rdx
add    $0x3,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x75(%rbp)
jne    134d <main+0x1dd>
lea    -0x70(%rbp),%rdi
lea    0xd2c(%rip),%rsi
mov    $0x6,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <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 0xf00(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xee4(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xecc(%rip),%rsi
mov    %rsp,%rdi
mov    $0x3,%edx
call   1060 <mempcpy@plt>
lea    0x3(%rsp),%r15
xor    %ebx,%ebx
mov    $0x0,%edi
cmp    %r15,%rax
jne    11d9 <main+0x99>
lea    0xeab(%rip),%rsi
mov    %rsp,%rdi
mov    $0x8,%edx
call   1030 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
lea    0xe86(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1060 <mempcpy@plt>
lea    0x4(%rsp),%rcx
cmp    %rcx,%rax
jne    1217 <main+0xd7>
lea    0xe68(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1030 <memcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %ebx,%edi
call   1040 <assert@plt>
movl   $0x6f6f66,(%rsp)
lea    0xe3f(%rip),%rsi
mov    %rsp,%r14
mov    $0x4,%edx
mov    %r14,%rdi
call   1030 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
lea    0xe27(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1050 <stpncpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1050 <stpncpy@plt>
lea    0x2(%rsp),%rcx
xor    %ebx,%ebx
mov    $0x0,%edi
cmp    %rcx,%rax
jne    129d <main+0x15d>
lea    0xdf3(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1030 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
lea    0xdd6(%rip),%rsi
mov    %rsp,%rdi
mov    $0x6,%edx
call   1050 <stpncpy@plt>
cmp    %r15,%rax
jne    12d6 <main+0x196>
lea    0xda2(%rip),%rsi
mov    %rsp,%rdi
mov    $0x6,%edx
call   1030 <memcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %ebx,%edi
call   1040 <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"
@.str.4 = [4 x i8] c"xyz\00"
@.str.5 = [7 x i8] c"xyz\00\00\00\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)
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%63 = call i8* @stpncpy(i8* %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 6)
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%65 = getelementptr inbounds i8, i8* %64, i64 3
%66 = icmp eq i8* %63, %65
br i1 %66, label %67, label %72
67: ; preds = %58
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%69 = call i32 @memcmp(i8* %68, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 6)
%70 = icmp ne i32 %69, 0
%71 = xor i1 %70, true
br label %72
72: ; preds = %67, %58
%73 = phi i1 [ false, %58 ], [ %71, %67 ]
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
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.1 = [8 x i8] c"foobber\00"
@.str.2 = [4 x i8] c"bar\00"
@.str.3 = [4 x i8] c"bao\00"
@.str.4 = [4 x i8] c"xyz\00"
@.str.5 = [7 x i8] c"xyz\00\00\00\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
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 bitcast (i32 (i8*, i8*, i32)* @memcmp to i32 (i8*, i8*, i64)*)(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 8)
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %6, %0
%11 = phi i32 [ 0, %0 ], [ %9, %6 ]
%12 = call i32 @assert(i32 %11)
%13 = call i8* @mempcpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = call i32 bitcast (i32 (i8*, i8*, i32)* @memcmp to i32 (i8*, i8*, i64)*)(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 4)
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %16, %10
%21 = phi i32 [ 0, %10 ], [ %19, %16 ]
%22 = call i32 @assert(i32 %21)
%23 = bitcast [100 x i8]* %1 to i32*
store i32 7303014, i32* %23
%24 = call i32 bitcast (i32 (i8*, i8*, i32)* @memcmp to i32 (i8*, i8*, i64)*)(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 4)
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = call i8* @stpncpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%29 = call i8* @stpncpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%31 = icmp eq i8* %29, %30
br i1 %31, label %32, label %36
32: ; preds = %20
%33 = call i32 bitcast (i32 (i8*, i8*, i32)* @memcmp to i32 (i8*, i8*, i64)*)(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 4)
%34 = icmp eq i32 %33, 0
%35 = zext i1 %34 to i32
br label %36
36: ; preds = %32, %20
%37 = phi i32 [ 0, %20 ], [ %35, %32 ]
%38 = call i32 @assert(i32 %37)
%39 = call i8* @stpncpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 6)
%40 = icmp eq i8* %39, %4
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = call i32 @memcmp(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 6)
%43 = icmp eq i32 %42, 0
%44 = zext i1 %43 to i32
br label %45
45: ; preds = %41, %36
%46 = phi i32 [ 0, %36 ], [ %44, %41 ]
%47 = call i32 @assert(i32 %46)
ret i32 0
}