#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*/ printf(char *, ...);
int strlen1(char *);
int strlen2(char *);
int main() {
  char test1[] = "This is only a test string ok";
  char test2[] = "This is a longer test string than the first one";
  printf("---- strlen1 ----\n");
  printf("test1 length = %d\n", strlen1(test1));
  printf("test2 length = %d\n", strlen1(test2));
  printf("\n---- strlen2 ----\n");
  printf("test1 length = %d\n", strlen2(test1));
  printf("test2 length = %d\n", strlen2(test2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xea4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea2(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xe9c(%rip),%ax
mov    %ax,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0x30,%edx
call   1050 <memcpy@plt>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen1@plt>
mov    %eax,%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1030 <strlen1@plt>
mov    %eax,%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1060 <strlen2@plt>
mov    %eax,%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1060 <strlen2@plt>
mov    %eax,%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
movups 0xebc(%rip),%xmm0
movups %xmm0,0xe(%rsp)
movaps 0xea2(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xed7(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xebb(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xee9(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strlen1@plt>
lea    0xeac(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
call   1030 <strlen1@plt>
lea    0xe9f(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb1(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1060 <strlen2@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1060 <strlen2@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.test1 = [30 x i8] c"This is only a test string ok\00"
@__const.main.test2 = [48 x i8] c"This is a longer test string than the first one\00"
@.str = [19 x i8] c"---- strlen1 ----\0A\00"
@.str.1 = [19 x i8] c"test1 length = %d\0A\00"
@.str.2 = [19 x i8] c"test2 length = %d\0A\00"
@.str.3 = [20 x i8] c"\0A---- strlen2 ----\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca [48 x i8]
store i32 0, i32* %1
%4 = bitcast [30 x i8]* %2 to i8*
%5 = bitcast [48 x i8]* %3 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%8 = call i32 @strlen1(i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%11 = call i32 @strlen1(i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%15 = call i32 @strlen2(i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%18 = call i32 @strlen2(i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %18)
ret i32 0
}

LLVM IR (-O2):
@__const.main.test1 = [30 x i8] c"This is only a test string ok\00"
@__const.main.test2 = [48 x i8] c"This is a longer test string than the first one\00"
@.str.1 = [19 x i8] c"test1 length = %d\0A\00"
@.str.2 = [19 x i8] c"test2 length = %d\0A\00"
@str = [18 x i8] c"---- strlen1 ----\00"
@str.4 = [19 x i8] c"\0A---- strlen2 ----\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca [48 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [48 x i8], [48 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%6 = call i32 @strlen1(i8* %3)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = call i32 @strlen1(i8* %4)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
%11 = call i32 @strlen2(i8* %3)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @strlen2(i8* %4)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %13)
ret i32 0
}