#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
main() {
  unsigned char cadena[41];
  int i = 0, car;
  printf("Introducir un texto: ");
  while ((car = getchar()) != '\n' && i < 41 - 1) {
    cadena[i] = car;
    i++;
  }
  cadena[i] = 0;
  printf("Texto introducido:  %s\n", cadena);
  printf("Longitud del texto: %d\n", i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x38(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x39(%rbp)
je     1168 <main+0x48>
cmpl   $0x28,-0x34(%rbp)
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1178 <main+0x58>
jmp    1193 <main+0x73>
mov    -0x38(%rbp),%eax
mov    %al,%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1144 <main+0x24>
movslq -0x34(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xed2(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     116c <main+0x4c>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %al,(%rsp,%rbx,1)
lea    0x1(%rbx),%r14
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     116c <main+0x4c>
cmp    $0x27,%rbx
mov    %r14,%rbx
jb     1150 <main+0x30>
mov    %r14d,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe9c(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea3(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Introducir un texto: \00"
@.str.1 = [24 x i8] c"Texto introducido: %s\0A\00"
@.str.2 = [24 x i8] c"Longitud del texto: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [41 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %14, %0
%7 = call i32 (...) @getchar()
store i32 %7, i32* %4
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 40
br label %12
12: ; preds = %9, %6
%13 = phi i1 [ false, %6 ], [ %11, %9 ]
br i1 %13, label %14, label %22
14: ; preds = %12
%15 = load i32, i32* %4
%16 = trunc i32 %15 to i8
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 %18
store i8 %16, i8* %19
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %6
22: ; preds = %12
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [22 x i8] c"Introducir un texto: \00"
@.str.1 = [24 x i8] c"Texto introducido: %s\0A\00"
@.str.2 = [24 x i8] c"Longitud del texto: %d\0A\00"
define i32 @main() {
%1 = alloca [41 x i8]
%2 = getelementptr inbounds [41 x i8], [41 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 = tail call i32 (...) @getchar()
%5 = icmp eq i32 %4, 10
br i1 %5, label %18, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %11, %6 ], [ 0, %0 ]
%8 = phi i32 [ %12, %6 ], [ %4, %0 ]
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds [41 x i8], [41 x i8]* %1, i64 0, i64 %7
store i8 %9, i8* %10
%11 = add nuw nsw i64 %7, 1
%12 = tail call i32 (...) @getchar()
%13 = icmp ne i32 %12, 10
%14 = icmp ult i64 %7, 39
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %6, label %16
16: ; preds = %6
%17 = trunc i64 %11 to i32
br label %18
18: ; preds = %16, %0
%19 = phi i32 [ 0, %0 ], [ %17, %16 ]
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [41 x i8], [41 x i8]* %1, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %19)
ret i32 0
}