#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*/ free(char *);
scalar_t__ strcmp(char *, char *);
char *strndup(char *, int);
int main(void) {
  char *copy = NULL;
  char str[] = "abcdefghijklmnopqrstuvwxyz";
  copy = strndup(str, 10);
  assert(0 == strcmp("abcdefghij", copy));
  free(copy);
  copy = strndup(str, 5000);
  assert('\0' == copy[5000]);
  free(copy);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0xea2(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe9f(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe9c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe99(%rip),%ax
mov    %ax,-0x18(%rbp)
mov    0xe91(%rip),%al
mov    %al,-0x16(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strndup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    -0x30(%rbp),%rdi
mov    $0x1388,%esi
call   1040 <strndup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1388(%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movups 0xebd(%rip),%xmm0
movups %xmm0,0xb(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strndup@plt>
mov    %rax,%rbx
lea    0xea3(%rip),%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
mov    $0x1388,%esi
call   1040 <strndup@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmpb   $0x0,0x1388(%rax)
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.str = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str = [11 x i8] c"abcdefghij\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [27 x i8]
store i32 0, i32* %1
store i8* null, i8** %2
%4 = bitcast [27 x i8]* %3 to i8*
%5 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 0
%6 = call i8* @strndup(i8* %5, i32 10)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strcmp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = icmp eq i64 0, %8
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %2
%13 = call i32 @free(i8* %12)
%14 = getelementptr inbounds [27 x i8], [27 x i8]* %3, i64 0, i64 0
%15 = call i8* @strndup(i8* %14, i32 5000)
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 5000
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 0, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8*, i8** %2
%24 = call i32 @free(i8* %23)
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@.str = [11 x i8] c"abcdefghij\00"
define i32 @main() {
%1 = alloca [27 x i8]
%2 = getelementptr inbounds [27 x i8], [27 x i8]* %1, i64 0, i64 0
%3 = call i8* @strndup(i8* %2, i32 10)
%4 = tail call i64 @strcmp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = icmp eq i64 %4, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @free(i8* %3)
%9 = call i8* @strndup(i8* %2, i32 5000)
%10 = getelementptr inbounds i8, i8* %9, i64 5000
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @free(i8* %9)
ret i32 0
}