#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 */
char *alloc(int);
int /*<<< orphan*/ printf(char *, ...);
int strlen2(char *);
int main(void) {
  char *p;
  p = alloc(10);
  *p = 'D';
  *(p + 1) = 'a';
  *(p + 2) = 'n';
  *(p + 3) = 'i';
  *(p + 4) = 'e';
  *(p + 5) = 'l';
  *(p + 6) = '\0';
  int i;
  for (i = 0; *(p + i) != '\0'; i++)
    printf("%c", *(p + i));
  printf("\n");
  int size = strlen2(p);
  printf("Size of string -> %d\n", size);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
call   1050 <alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x44,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x61,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x6e,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x69,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x65,0x4(%rax)
mov    -0x10(%rbp),%rax
movb   $0x6c,0x5(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x6(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11c8 <main+0x98>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <main+0x5b>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen2@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0xa,%edi
call   1060 <alloc@plt>
mov    %rax,%r14
movl   $0x696e6144,(%rax)
lea    0x1(%rax),%rbx
movw   $0x6c65,0x4(%rax)
movb   $0x0,0x6(%rax)
mov    $0x44,%al
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <main+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1050 <strlen2@plt>
lea    0xe64(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [22 x i8] c"Size of string -> %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i8* @alloc(i32 10)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
store i8 68, i8* %6
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8 97, i8* %8
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 2
store i8 110, i8* %10
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 3
store i8 105, i8* %12
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 4
store i8 101, i8* %14
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 5
store i8 108, i8* %16
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 6
store i8 0, i8* %18
store i32 0, i32* %3
br label %19
19: ; preds = %35, %0
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %19
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %27
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %19
38: ; preds = %19
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%40 = load i8*, i8** %2
%41 = call i32 @strlen2(i8* %40)
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %42)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [22 x i8] c"Size of string -> %d\0A\00"
define i32 @main() {
%1 = tail call i8* @alloc(i32 10)
store i8 68, i8* %1
%2 = getelementptr inbounds i8, i8* %1, i64 1
store i8 97, i8* %2
%3 = getelementptr inbounds i8, i8* %1, i64 2
store i8 110, i8* %3
%4 = getelementptr inbounds i8, i8* %1, i64 3
store i8 105, i8* %4
%5 = getelementptr inbounds i8, i8* %1, i64 4
store i8 101, i8* %5
%6 = getelementptr inbounds i8, i8* %1, i64 5
store i8 108, i8* %6
%7 = getelementptr inbounds i8, i8* %1, i64 6
store i8 0, i8* %7
br label %8
8: ; preds = %0, %8
%9 = phi i64 [ 0, %0 ], [ %13, %8 ]
%10 = phi i8 [ 68, %0 ], [ %15, %8 ]
%11 = sext i8 %10 to i32
%12 = tail call i32 @putchar(i32 %11)
%13 = add nuw i64 %9, 1
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %8
%18 = tail call i32 @putchar(i32 10)
%19 = tail call i32 @strlen2(i8* %1)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %19)
ret i32 0
}