#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*/ Panic(char *);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
int strlen(char *);
void Check_strdup(void) {
  char *ptr;
  ptr = strdup("1234567890");
  if (!ptr)
    Panic("strdup");
  if (ptr[10] != '\0')
    Panic("strdup NULL byte");
  if (strlen(ptr) != 10)
    Panic("strdup string length");
  free(ptr);
}


x86 assembly (clang, -O0):
<Check_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116f <Check_strdup+0x2f>
lea    0xea1(%rip),%rdi
call   1050 <Panic@plt>
mov    -0x8(%rbp),%rax
movsbl 0xa(%rax),%eax
cmp    $0x0,%eax
je     118c <Check_strdup+0x4c>
lea    0xe8b(%rip),%rdi
call   1050 <Panic@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xa,%eax
je     11aa <Check_strdup+0x6a>
lea    0xe7e(%rip),%rdi
call   1050 <Panic@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Check_strdup>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1189 <Check_strdup+0x49>
cmpb   $0x0,0xa(%rbx)
je     1167 <Check_strdup+0x27>
lea    0xeb0(%rip),%rdi
call   1050 <Panic@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0xa,%eax
je     1180 <Check_strdup+0x40>
lea    0xea8(%rip),%rdi
call   1050 <Panic@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <free@plt>
lea    0xe7b(%rip),%rdi
call   1050 <Panic@plt>
cmpb   $0x0,0xa(%rbx)
jne    115b <Check_strdup+0x1b>
jmp    1167 <Check_strdup+0x27>

LLVM IR (-O0):
@.str = [11 x i8] c"1234567890\00"
@.str.1 = [7 x i8] c"strdup\00"
@.str.2 = [17 x i8] c"strdup NULL byte\00"
@.str.3 = [21 x i8] c"strdup string length\00"
define void @Check_strdup() {
%1 = alloca i8*
%2 = call i8* @strdup(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %2, i8** %1
%3 = load i8*, i8** %1
%4 = icmp ne i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @Panic(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = load i8*, i8** %1
%9 = getelementptr inbounds i8, i8* %8, i64 10
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 @Panic(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = load i8*, i8** %1
%17 = call i32 @strlen(i8* %16)
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @Panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i8*, i8** %1
%23 = call i32 @free(i8* %22)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"1234567890\00"
@.str.1 = [7 x i8] c"strdup\00"
@.str.2 = [17 x i8] c"strdup NULL byte\00"
@.str.3 = [21 x i8] c"strdup string length\00"
define void @Check_strdup() {
%1 = tail call dereferenceable_or_null(11) i8* @strdup(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @Panic(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = getelementptr inbounds i8, i8* %1, i64 10
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @Panic(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
%12 = tail call i32 @strlen(i8* %1)
%13 = icmp eq i32 %12, 10
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @Panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = tail call i32 @free(i8* %1)
ret void
}