#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 EXIT_SUCCESS;
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char **argv) {
  char cadena[51];
  int i = 1, car;
  printf("Introduce un texto: ");
  scanf("%c", cadena);
  while (i < 51 - 1 && (car = getchar()) != '0') {
    cadena[i] = car;
    i++;
  }
  cadena[i] = 0;
  printf("La longitud del texto es de: %d letras", i);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x54(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xeaf(%rip),%rdi
call   1050 <scanf@plt>
xor    %eax,%eax
cmpl   $0x32,-0x54(%rbp)
mov    %al,-0x59(%rbp)
jge    118d <main+0x5d>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x58(%rbp)
cmp    $0x30,%eax
setne  %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    119d <main+0x6d>
jmp    11b8 <main+0x88>
mov    -0x58(%rbp),%eax
mov    %al,%cl
movslq -0x54(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    116b <main+0x3b>
movslq -0x54(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
mov    -0x54(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x30,%eax
je     117e <main+0x4e>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x32,%rbx
jne    1160 <main+0x30>
mov    $0x32,%ebx
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe8d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Introduce un texto: \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [39 x i8] c"La longitud del texto es de: %d letras\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [51 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [51 x i8], [51 x i8]* %6, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %20, %2
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 50
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 (...) @getchar()
store i32 %16, i32* %8
%17 = icmp ne i32 %16, 48
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ false, %12 ], [ %17, %15 ]
br i1 %19, label %20, label %28
20: ; preds = %18
%21 = load i32, i32* %8
%22 = trunc i32 %21 to i8
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [51 x i8], [51 x i8]* %6, i64 0, i64 %24
store i8 %22, i8* %25
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %12
28: ; preds = %18
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [51 x i8], [51 x i8]* %6, i64 0, i64 %30
store i8 0, i8* %31
%32 = load i32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* @EXIT_SUCCESS
ret i32 %34
}

LLVM IR (-O2):
@.str = [21 x i8] c"Introduce un texto: \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [39 x i8] c"La longitud del texto es de: %d letras\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [51 x i8]
%4 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %7
7: ; preds = %2, %11
%8 = phi i64 [ 1, %2 ], [ %14, %11 ]
%9 = call i32 (...) @getchar()
%10 = icmp eq i32 %9, 48
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = trunc i32 %9 to i8
%13 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 %8
store i8 %12, i8* %13
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, 50
br i1 %15, label %18, label %7
16: ; preds = %7
%17 = trunc i64 %8 to i32
br label %18
18: ; preds = %11, %16
%19 = phi i32 [ %17, %16 ], [ 50, %11 ]
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}