void test_int_lenstr(void) {
  printf("------------------------\n");
  printf("TESTING:: test_int_lenstr \n");
  int my_int = 24;
  unsigned char int_len = sizeof(my_int);
  unsigned char *int_result = generate_lenstr(&my_int, int_len);
  printf("int last_i-1:: '%u'\n", int_result[0]);
  unsigned int res_int_len;
  int *raw_int = generate_raw(int_result, &res_int_len);
  printf("int '%d'\n", *raw_int);
  printf("int_len '%d'\n", res_int_len);
  free(int_result);
  free(raw_int);
}


x86 assembly (clang, -O0):
<test_int_lenstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x18,-0x4(%rbp)
movb   $0x4,-0x5(%rbp)
movzbl -0x5(%rbp),%esi
lea    -0x4(%rbp),%rdi
mov    $0x0,%al
call   1040 <generate_lenstr@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <generate_raw@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_int_lenstr>:
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
call   1040 <puts@plt>
lea    0xedf(%rip),%rdi
call   1040 <puts@plt>
movl   $0x18,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <generate_lenstr@plt>
movslq %eax,%rbx
movzbl (%rbx),%esi
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <generate_raw@plt>
movslq %eax,%r14
mov    (%r14),%esi
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rsp),%esi
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"------------------------\0A\00"
@.str.1 = [28 x i8] c"TESTING:: test_int_lenstr \0A\00"
@.str.2 = [21 x i8] c"int last_i-1:: '%u'\0A\00"
@.str.3 = [10 x i8] c"int '%d'\0A\00"
@.str.4 = [14 x i8] c"int_len '%d'\0A\00"
define void @test_int_lenstr() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 24, i32* %1
store i8 4, i8* %2
%8 = load i8, i8* %2
%9 = zext i8 %8 to i32
%10 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @generate_lenstr to i32 (i32*, i32, ...)*)(i32* %1, i32 %9)
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %3
%19 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @generate_raw to i32 (i8*, i32*, ...)*)(i8* %18, i32* %4)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i32*
store i32* %21, i32** %5
%22 = load i32*, i32** %5
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %3
%28 = load i32*, i32** %5
%29 = bitcast i32* %28 to i8*
ret void
}

LLVM IR (-O2):
@.str.2 = [21 x i8] c"int last_i-1:: '%u'\0A\00"
@.str.3 = [10 x i8] c"int '%d'\0A\00"
@.str.4 = [14 x i8] c"int_len '%d'\0A\00"
@str = [25 x i8] c"------------------------\00"
@str.5 = [27 x i8] c"TESTING:: test_int_lenstr \00"
define void @test_int_lenstr() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
%5 = bitcast i32* %1 to i8*
store i32 24, i32* %1
%6 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @generate_lenstr to i32 (i32*, i32, ...)*)(i32* %1, i32 4)
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i8*
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = bitcast i32* %2 to i8*
%13 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @generate_raw to i32 (i8*, i32*, ...)*)(i8* %8, i32* %2)
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = inttoptr i64 %14 to i8*
ret void
}