#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*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ stderr;
char *stpncpy(char *, char *, size_t);
int strcmp(char *, char *);
size_t strlen(char *);
int strncmp(char *, char *, size_t);
int main(int argc, char **argv) {
  char a[] = "The spazzy orange tiger jumped over the tawny jaguar.";
  char *b, *c;
  char *d, *e;
  size_t l = strlen(a);
  fprintf(stderr, "strlen: %zd\n", l);
  b = (char *)malloc((l + 3));
  b[l] = 'X';
  b[l + 1] = 'X';
  b[l + 2] = 'X';
  c = stpncpy(b, a, l + 3);
  fprintf(stderr, "equal: %d\n", strcmp(a, b));
  fprintf(stderr, "retlen: %zd\n", c - b);
  fprintf(stderr, "last: '%c'\n", *(c - 1));
  fprintf(stderr, "zero0: %d\n", *c);
  fprintf(stderr, "zero1: %d\n", *(c + 1));
  fprintf(stderr, "zero2: %d\n", *(c + 2));
  d = (char *)malloc(l - 1);
  e = stpncpy(d, b, l - 1);
  fprintf(stderr, "equal: %d\n", strncmp(b, d, l - 1));
  fprintf(stderr, "retlen: %zd\n", e - d);
  fprintf(stderr, "last: '%c'\n", *(e - 1));
  free(b);
  free(d);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x36,%edx
call   1080 <memcpy@plt>
lea    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x78(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x78(%rbp),%rax
lea    0xe67(%rip),%rsi
movsbl %al,%edx
call   1070 <fprintf@plt>
mov    -0x78(%rbp),%rdi
add    $0x3,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
movb   $0x58,(%rax,%rcx,1)
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
movb   $0x58,0x1(%rax,%rcx,1)
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
movb   $0x58,0x2(%rax,%rcx,1)
mov    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x78(%rbp),%rdx
add    $0x3,%rdx
call   10a0 <stpncpy@plt>
mov    %rax,-0x60(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1060 <strcmp@plt>
mov    -0x80(%rbp),%edi
lea    0xdf9(%rip),%rsi
movsbl %al,%edx
call   1070 <fprintf@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
mov    -0x60(%rbp),%rax
mov    -0x58(%rbp),%rcx
sub    %rcx,%rax
lea    0xde1(%rip),%rsi
movsbl %al,%edx
call   1070 <fprintf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    -0x60(%rbp),%rax
lea    0xdd2(%rip),%rsi
movsbl -0x1(%rax),%edx
call   1070 <fprintf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
mov    -0x60(%rbp),%rax
lea    0xdc1(%rip),%rsi
movsbl (%rax),%edx
call   1070 <fprintf@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
mov    -0x60(%rbp),%rax
lea    0xdb0(%rip),%rsi
movsbl 0x1(%rax),%edx
call   1070 <fprintf@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
mov    -0x60(%rbp),%rax
lea    0xd9e(%rip),%rsi
movsbl 0x2(%rax),%edx
call   1070 <fprintf@plt>
mov    -0x78(%rbp),%rdi
sub    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x78(%rbp),%rdx
sub    $0x1,%rdx
call   10a0 <stpncpy@plt>
mov    %rax,-0x70(%rbp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x78(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <strncmp@plt>
mov    -0x7c(%rbp),%edi
lea    0xd06(%rip),%rsi
movsbl %al,%edx
call   1070 <fprintf@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rax
mov    -0x68(%rbp),%rcx
sub    %rcx,%rax
lea    0xcee(%rip),%rsi
movsbl %al,%edx
call   1070 <fprintf@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rax
lea    0xcdf(%rip),%rsi
movsbl -0x1(%rax),%edx
call   1070 <fprintf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movaps 0xe9b(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe7f(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe63(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x2e72617567616a,%rax
mov    %rax,0x2e(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    0x2e1b(%rip),%r13
mov    0x0(%r13),%edi
movsbl %bl,%edx
lea    0xe63(%rip),%rsi
call   1070 <fprintf@plt>
lea    0x3(%rbx),%rbp
mov    %rbp,%rdi
call   1080 <malloc@plt>
mov    %rax,%r14
movw   $0x5858,(%rax,%rbx,1)
movb   $0x58,0x2(%rax,%rbx,1)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1090 <stpncpy@plt>
mov    %rax,%rbp
mov    0x0(%r13),%r12d
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
movsbl %al,%edx
lea    0xe27(%rip),%rsi
mov    %r12d,%edi
call   1070 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %ebp,%eax
sub    %r14d,%eax
movsbl %al,%edx
lea    0xe17(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x0(%r13),%edi
movsbl -0x1(%rbp),%edx
lea    0xe10(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x0(%r13),%edi
movsbl 0x0(%rbp),%edx
lea    0xe08(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x0(%r13),%edi
movsbl 0x1(%rbp),%edx
lea    0xdff(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x0(%r13),%edi
movsbl 0x2(%rbp),%edx
lea    0xdf6(%rip),%rsi
call   1070 <fprintf@plt>
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1090 <stpncpy@plt>
mov    %rax,%r15
mov    0x0(%r13),%r12d
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <strncmp@plt>
movsbl %al,%edx
mov    %r12d,%edi
lea    0xd78(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r15d,%eax
sub    %ebp,%eax
movsbl %al,%edx
lea    0xd6b(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x0(%r13),%edi
movsbl -0x1(%r15),%edx
lea    0xd63(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.a = [54 x i8] c"The spazzy orange tiger jumped over the tawny jaguar.\00"
@stderr = global i32 0
@.str = [13 x i8] c"strlen: %zd\0A\00"
@.str.1 = [11 x i8] c"equal: %d\0A\00"
@.str.2 = [13 x i8] c"retlen: %zd\0A\00"
@.str.3 = [12 x i8] c"last: '%c'\0A\00"
@.str.4 = [11 x i8] c"zero0: %d\0A\00"
@.str.5 = [11 x i8] c"zero1: %d\0A\00"
@.str.6 = [11 x i8] c"zero2: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [54 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [54 x i8]* %6 to i8*
%13 = getelementptr inbounds [54 x i8], [54 x i8]* %6, i64 0, i64 0
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %11
%15 = load i32, i32* @stderr
%16 = load i64, i64* %11
%17 = trunc i64 %16 to i8
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 signext %17)
%19 = load i64, i64* %11
%20 = add i64 %19, 3
%21 = call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = load i64, i64* %11
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 88, i8* %25
%26 = load i8*, i8** %7
%27 = load i64, i64* %11
%28 = add i64 %27, 1
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 88, i8* %29
%30 = load i8*, i8** %7
%31 = load i64, i64* %11
%32 = add i64 %31, 2
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 88, i8* %33
%34 = load i8*, i8** %7
%35 = getelementptr inbounds [54 x i8], [54 x i8]* %6, i64 0, i64 0
%36 = load i64, i64* %11
%37 = add i64 %36, 3
%38 = call i8* @stpncpy(i8* %34, i8* %35, i64 %37)
store i8* %38, i8** %8
%39 = load i32, i32* @stderr
%40 = getelementptr inbounds [54 x i8], [54 x i8]* %6, i64 0, i64 0
%41 = load i8*, i8** %7
%42 = call i32 @strcmp(i8* %40, i8* %41)
%43 = trunc i32 %42 to i8
%44 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 signext %43)
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %8
%47 = load i8*, i8** %7
%48 = ptrtoint i8* %46 to i64
%49 = ptrtoint i8* %47 to i64
%50 = sub i64 %48, %49
%51 = trunc i64 %50 to i8
%52 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8 signext %51)
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %8
%55 = getelementptr inbounds i8, i8* %54, i64 -1
%56 = load i8, i8* %55
%57 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8 signext %56)
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %8
%60 = load i8, i8* %59
%61 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8 signext %60)
%62 = load i32, i32* @stderr
%63 = load i8*, i8** %8
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = load i8, i8* %64
%66 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8 signext %65)
%67 = load i32, i32* @stderr
%68 = load i8*, i8** %8
%69 = getelementptr inbounds i8, i8* %68, i64 2
%70 = load i8, i8* %69
%71 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8 signext %70)
%72 = load i64, i64* %11
%73 = sub i64 %72, 1
%74 = call i64 @malloc(i64 %73)
%75 = inttoptr i64 %74 to i8*
store i8* %75, i8** %9
%76 = load i8*, i8** %9
%77 = load i8*, i8** %7
%78 = load i64, i64* %11
%79 = sub i64 %78, 1
%80 = call i8* @stpncpy(i8* %76, i8* %77, i64 %79)
store i8* %80, i8** %10
%81 = load i32, i32* @stderr
%82 = load i8*, i8** %7
%83 = load i8*, i8** %9
%84 = load i64, i64* %11
%85 = sub i64 %84, 1
%86 = call i32 @strncmp(i8* %82, i8* %83, i64 %85)
%87 = trunc i32 %86 to i8
%88 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 signext %87)
%89 = load i32, i32* @stderr
%90 = load i8*, i8** %10
%91 = load i8*, i8** %9
%92 = ptrtoint i8* %90 to i64
%93 = ptrtoint i8* %91 to i64
%94 = sub i64 %92, %93
%95 = trunc i64 %94 to i8
%96 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8 signext %95)
%97 = load i32, i32* @stderr
%98 = load i8*, i8** %10
%99 = getelementptr inbounds i8, i8* %98, i64 -1
%100 = load i8, i8* %99
%101 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8 signext %100)
%102 = load i8*, i8** %7
%103 = call i32 @free(i8* %102)
%104 = load i8*, i8** %9
%105 = call i32 @free(i8* %104)
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [54 x i8] c"The spazzy orange tiger jumped over the tawny jaguar.\00"
@stderr = global i32 0
@.str = [13 x i8] c"strlen: %zd\0A\00"
@.str.1 = [11 x i8] c"equal: %d\0A\00"
@.str.2 = [13 x i8] c"retlen: %zd\0A\00"
@.str.3 = [12 x i8] c"last: '%c'\0A\00"
@.str.4 = [11 x i8] c"zero0: %d\0A\00"
@.str.5 = [11 x i8] c"zero1: %d\0A\00"
@.str.6 = [11 x i8] c"zero2: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [54 x i8]
%4 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 0
%5 = call i64 @strlen(i8* %4)
%6 = load i32, i32* @stderr
%7 = trunc i64 %5 to i8
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 signext %7)
%9 = add i64 %5, 3
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds i8, i8* %11, i64 %5
store i8 88, i8* %12
%13 = add i64 %5, 1
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 88, i8* %14
%15 = add i64 %5, 2
%16 = getelementptr inbounds i8, i8* %11, i64 %15
store i8 88, i8* %16
%17 = call i8* @stpncpy(i8* %11, i8* %4, i64 %9)
%18 = load i32, i32* @stderr
%19 = call i32 @strcmp(i8* %4, i8* dereferenceable(1) %11)
%20 = trunc i32 %19 to i8
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 signext %20)
%22 = load i32, i32* @stderr
%23 = ptrtoint i8* %17 to i64
%24 = sub i64 %23, %10
%25 = trunc i64 %24 to i8
%26 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8 signext %25)
%27 = load i32, i32* @stderr
%28 = getelementptr inbounds i8, i8* %17, i64 -1
%29 = load i8, i8* %28
%30 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8 signext %29)
%31 = load i32, i32* @stderr
%32 = load i8, i8* %17
%33 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8 signext %32)
%34 = load i32, i32* @stderr
%35 = getelementptr inbounds i8, i8* %17, i64 1
%36 = load i8, i8* %35
%37 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8 signext %36)
%38 = load i32, i32* @stderr
%39 = getelementptr inbounds i8, i8* %17, i64 2
%40 = load i8, i8* %39
%41 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8 signext %40)
%42 = add i64 %5, -1
%43 = tail call i64 @malloc(i64 %42)
%44 = inttoptr i64 %43 to i8*
%45 = tail call i8* @stpncpy(i8* %44, i8* %11, i64 %42)
%46 = load i32, i32* @stderr
%47 = tail call i32 @strncmp(i8* %11, i8* %44, i64 %42)
%48 = trunc i32 %47 to i8
%49 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 signext %48)
%50 = load i32, i32* @stderr
%51 = ptrtoint i8* %45 to i64
%52 = sub i64 %51, %43
%53 = trunc i64 %52 to i8
%54 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8 signext %53)
%55 = load i32, i32* @stderr
%56 = getelementptr inbounds i8, i8* %45, i64 -1
%57 = load i8, i8* %56
%58 = tail call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8 signext %57)
%59 = tail call i32 @free(i8* %11)
%60 = tail call i32 @free(i8* %44)
ret i32 0
}