#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char *st = malloc(256);
  printf("--------------------PROGRAM THAT FINDS LENGTH OF A "
         "STRING--------------------\n\n\n\n\n");
  printf("Enter a string: ");
  scanf("%255s", st);
  printf("\nThe length of \"%s\" is %d.\n\n", st, strlen(st));
  free(st);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xed0(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe82(%rip),%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe71(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [83 x i8] c"--------------------PROGRAM THAT FINDS LENGTH OF A STRING--------------------\0A\0A\0A\0A\0A\00"
@.str.1 = [17 x i8] c"Enter a string: \00"
@.str.2 = [6 x i8] c"%255s\00"
@.str.3 = [29 x i8] c"\0AThe length of \22%s\22 is %d.\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @malloc(i32 256)
store i8* %3, i8** %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %8, i32 %10)
%12 = load i8*, i8** %2
%13 = call i32 @free(i8* %12)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"Enter a string: \00"
@.str.2 = [6 x i8] c"%255s\00"
@.str.3 = [29 x i8] c"\0AThe length of \22%s\22 is %d.\0A\0A\00"
@str = [82 x i8] c"--------------------PROGRAM THAT FINDS LENGTH OF A STRING--------------------\0A\0A\0A\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %5)
%7 = tail call i32 @free(i8* %1)
ret i32 0
}