#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 */
size_t StrGetLength(char const *);
int /*<<< orphan*/ printf(char *, ...);
size_t strlen(char const *);
void TestStrGetLength() {
  const char str1[] = "12345678901234567890";
  const char str2[] = "12345678901234567890\0 1234567";
  const char str_empty[] = "";
  size_t res1, res2;
  printf("===========================\n"
         "Test StrGetLength\n"
         "===========================\n");
  printf("Test1:\n");
  res1 = StrGetLength(str1);
  res2 = strlen(str1);
  (res1 == res2) ? printf("Correct!\n") : printf("Wrong!\n");
  printf("Your     Answer: [%d]\n", (int)res1);
  printf("String.h Answer: [%d]\n", (int)res2);
  printf("\nTest2:\n");
  res1 = StrGetLength(str2);
  res2 = strlen(str2);
  (res1 == res2) ? printf("Correct!\n") : printf("Wrong!\n");
  printf("Your     Answer: [%d]\n", (int)res1);
  printf("String.h Answer: [%d]\n", (int)res2);
  printf("\nTest3:\n");
  res1 = StrGetLength(str_empty);
  res2 = strlen(str_empty);
  (res1 == res2) ? printf("Correct!\n") : printf("Wrong!\n");
  printf("Your     Answer: [%d]\n", (int)res1);
  printf("String.h Answer: [%d]\n", (int)res2);
}


x86 assembly (clang, -O0):
<TestStrGetLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeac(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xea7(%rip),%al
mov    %al,-0xc(%rbp)
mov    0xea9(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea6(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea1(%rip),%eax
mov    %eax,-0x28(%rbp)
mov    0xe9b(%rip),%ax
mov    %ax,-0x24(%rbp)
lea    -0x41(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1050 <StrGetLength@plt>
mov    %rax,-0x50(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x58(%rbp),%rax
jne    120c <TestStrGetLength+0xcc>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121a <TestStrGetLength+0xda>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %eax,%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rax
mov    %eax,%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1050 <StrGetLength@plt>
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x58(%rbp),%rax
jne    128b <TestStrGetLength+0x14b>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1299 <TestStrGetLength+0x159>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %eax,%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rax
mov    %eax,%esi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x41(%rbp),%rdi
call   1050 <StrGetLength@plt>
mov    %rax,-0x50(%rbp)
lea    -0x41(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x58(%rbp),%rax
jne    130a <TestStrGetLength+0x1ca>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1318 <TestStrGetLength+0x1d8>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %eax,%esi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rax
mov    %eax,%esi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TestStrGetLength>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movaps 0xeab(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x30393837363534,%rax
mov    %rax,0x1d(%rsp)
movups 0xebe(%rip),%xmm0
movups %xmm0,0x3e(%rsp)
movaps 0xea4(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1d(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1060 <StrGetLength@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
cmp    %rax,%rbx
lea    0xf11(%rip),%rbp
lea    0xf03(%rip),%r12
mov    %r12,%rdi
cmove  %rbp,%rdi
call   1030 <puts@plt>
lea    0xe61(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe65(%rip),%r15
mov    %r15,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%r13
mov    %r13,%rdi
call   1060 <StrGetLength@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
cmp    %rax,%rbx
mov    %r12,%rdi
cmove  %rbp,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
lea    0xf(%rsp),%r13
mov    %r13,%rdi
call   1060 <StrGetLength@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
cmp    %rax,%rbx
cmove  %rbp,%r12
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.TestStrGetLength.str1 = [21 x i8] c"12345678901234567890\00"
@__const.TestStrGetLength.str2 = [30 x i8] c"12345678901234567890\00 1234567\00"
@.str = [75 x i8] c"===========================\0ATest StrGetLength\0A===========================\0A\00"
@.str.1 = [8 x i8] c"Test1:\0A\00"
@.str.2 = [10 x i8] c"Correct!\0A\00"
@.str.3 = [8 x i8] c"Wrong!\0A\00"
@.str.4 = [23 x i8] c"Your Answer: [%d]\0A\00"
@.str.5 = [23 x i8] c"String.h Answer: [%d]\0A\00"
@.str.6 = [9 x i8] c"\0ATest2:\0A\00"
@.str.7 = [9 x i8] c"\0ATest3:\0A\00"
define void @TestStrGetLength() {
%1 = alloca [21 x i8]
%2 = alloca [30 x i8]
%3 = alloca [1 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = bitcast [21 x i8]* %1 to i8*
%7 = bitcast [30 x i8]* %2 to i8*
%8 = bitcast [1 x i8]* %3 to i8*
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [21 x i8], [21 x i8]* %1, i64 0, i64 0
%12 = call i64 @StrGetLength(i8* %11)
store i64 %12, i64* %4
%13 = getelementptr inbounds [21 x i8], [21 x i8]* %1, i64 0, i64 0
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %5
%15 = load i64, i64* %4
%16 = load i64, i64* %5
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = phi i32 [ %19, %18 ], [ %21, %20 ]
%24 = load i64, i64* %4
%25 = trunc i64 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = load i64, i64* %5
%28 = trunc i64 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%32 = call i64 @StrGetLength(i8* %31)
store i64 %32, i64* %4
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%34 = call i64 @strlen(i8* %33)
store i64 %34, i64* %5
%35 = load i64, i64* %4
%36 = load i64, i64* %5
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %22
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %42
40: ; preds = %22
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %38
%43 = phi i32 [ %39, %38 ], [ %41, %40 ]
%44 = load i64, i64* %4
%45 = trunc i64 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = load i64, i64* %5
%48 = trunc i64 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%51 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%52 = call i64 @StrGetLength(i8* %51)
store i64 %52, i64* %4
%53 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%54 = call i64 @strlen(i8* %53)
store i64 %54, i64* %5
%55 = load i64, i64* %4
%56 = load i64, i64* %5
%57 = icmp eq i64 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %42
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %62
60: ; preds = %42
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %62
62: ; preds = %60, %58
%63 = phi i32 [ %59, %58 ], [ %61, %60 ]
%64 = load i64, i64* %4
%65 = trunc i64 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %65)
%67 = load i64, i64* %5
%68 = trunc i64 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %68)
ret void
}

LLVM IR (-O2):
@__const.TestStrGetLength.str1 = [21 x i8] c"12345678901234567890\00"
@__const.TestStrGetLength.str2 = [30 x i8] c"12345678901234567890\00 1234567\00"
@.str.4 = [23 x i8] c"Your Answer: [%d]\0A\00"
@.str.5 = [23 x i8] c"String.h Answer: [%d]\0A\00"
@str = [74 x i8] c"===========================\0ATest StrGetLength\0A===========================\00"
@str.8 = [7 x i8] c"Test1:\00"
@str.10 = [8 x i8] c"\0ATest2:\00"
@str.12 = [8 x i8] c"\0ATest3:\00"
@str.13 = [7 x i8] c"Wrong!\00"
@str.16 = [9 x i8] c"Correct!\00"
define void @TestStrGetLength() {
%1 = alloca [21 x i8]
%2 = alloca [30 x i8]
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [21 x i8], [21 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
store i8 0, i8* %6
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0))
%9 = call i64 @StrGetLength(i8* %4)
%10 = call i64 @strlen(i8* %4)
%11 = icmp eq i64 %9, %10
%12 = select i1 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.16, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.13, i64 0, i64 0)
%13 = call i32 @puts(i8* dereferenceable(1) %12)
%14 = trunc i64 %9 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = trunc i64 %10 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0))
%19 = call i64 @StrGetLength(i8* %5)
%20 = call i64 @strlen(i8* %5)
%21 = icmp eq i64 %19, %20
%22 = select i1 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.16, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.13, i64 0, i64 0)
%23 = call i32 @puts(i8* dereferenceable(1) %22)
%24 = trunc i64 %19 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = trunc i64 %20 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.12, i64 0, i64 0))
%29 = call i64 @StrGetLength(i8* %6)
%30 = call i64 @strlen(i8* %6)
%31 = icmp eq i64 %29, %30
%32 = select i1 %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.16, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.13, i64 0, i64 0)
%33 = call i32 @puts(i8* dereferenceable(1) %32)
%34 = trunc i64 %29 to i32
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = trunc i64 %30 to i32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %36)
ret void
}