#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char str[100], i = 0, length;
  printf("\n Enter the string : ");
  gets(str);
  while (str[i] != '\0')
    i++;
  length = i;
  printf("\n The length of the string is : %d", length);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x71(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <gets@plt>
movsbq -0x71(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     116d <main+0x4d>
mov    -0x71(%rbp),%al
add    $0x1,%al
mov    %al,-0x71(%rbp)
jmp    114d <main+0x2d>
mov    -0x71(%rbp),%al
mov    %al,-0x72(%rbp)
movsbl -0x72(%rbp),%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
lea    0xed5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rdi
call   1040 <gets@plt>
mov    $0xff,%al
nopl   0x0(%rax)
add    $0x1,%al
movsbq %al,%rcx
cmpb   $0x0,(%rsp,%rcx,1)
jne    1140 <main+0x20>
movsbl %al,%esi
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"\0A Enter the string : \00"
@.str.1 = [35 x i8] c"\0A The length of the string is : %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca i8
store i32 0, i32* %1
store i8 0, i8* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
br label %8
8: ; preds = %15, %0
%9 = load i8, i8* %3
%10 = sext i8 %9 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i8, i8* %3
%17 = add i8 %16, 1
store i8 %17, i8* %3
br label %8
18: ; preds = %8
%19 = load i8, i8* %3
store i8 %19, i8* %4
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"\0A Enter the string : \00"
@.str.1 = [35 x i8] c"\0A The length of the string is : %d\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
br label %5
5: ; preds = %5, %0
%6 = phi i8 [ 0, %0 ], [ %11, %5 ]
%7 = sext i8 %6 to i64
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
%11 = add i8 %6, 1
br i1 %10, label %12, label %5
12: ; preds = %5
%13 = sext i8 %6 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %13)
ret i32 0
}