#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 longitud_string(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(void) {
  char string1[] = "Hola a todos";
  char string2[200];
  char str[100];
  printf("cadena: %s\n", string1);
  printf("longitud cadena: %d\n", longitud_string(string1));
  strcpy(string2, "leer libros y revistas");
  printf("cadena2: %s\n", string2);
  printf("longitud cadena: %d\n\n", longitud_string(string2));
  printf("Lectura de STDIN: ---- # \n");
  while (scanf("%s", str) > 0) {
    printf("Longitud de %s: %d \n", str, longitud_string(str));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x11(%rbp)
mov    0xea5(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xea0(%rip),%al
mov    %al,-0x5(%rbp)
lea    -0x11(%rbp),%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x11(%rbp),%rdi
call   1060 <longitud_string@plt>
mov    %eax,%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xe0(%rbp),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe0(%rbp),%rdi
call   1060 <longitud_string@plt>
mov    %eax,%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x150(%rbp),%rsi
lea    0xe89(%rip),%rdi
call   1050 <scanf@plt>
cmp    $0x0,%rax
jle    123f <main+0xff>
lea    -0x150(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    -0x150(%rbp),%rdi
call   1060 <longitud_string@plt>
mov    -0x158(%rbp),%rsi
mov    %eax,%edx
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ec <main+0xac>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x150,%rsp
movabs $0x736f646f742061,%rax
mov    %rax,0x5(%rsp)
movabs $0x74206120616c6f48,%rax
61 20 74
mov    %rax,(%rsp)
lea    0xe8d(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <longitud_string@plt>
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe82(%rip),%rsi
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe82(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <longitud_string@plt>
lea    0xe76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
lea    0xe70(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1060 <scanf@plt>
test   %rax,%rax
jle    1247 <main+0xf7>
lea    0x10(%rsp),%rbx
lea    0xe58(%rip),%r14
lea    0xe4e(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <longitud_string@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
test   %rax,%rax
jg     1220 <main+0xd0>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.string1 = [13 x i8] c"Hola a todos\00"
@.str = [12 x i8] c"cadena: %s\0A\00"
@.str.1 = [21 x i8] c"longitud cadena: %d\0A\00"
@.str.2 = [23 x i8] c"leer libros y revistas\00"
@.str.3 = [13 x i8] c"cadena2: %s\0A\00"
@.str.4 = [22 x i8] c"longitud cadena: %d\0A\0A\00"
@.str.5 = [27 x i8] c"Lectura de STDIN: ---- # \0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [21 x i8] c"Longitud de %s: %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [13 x i8]
%3 = alloca [200 x i8]
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = bitcast [13 x i8]* %2 to i8*
%6 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%9 = call i32 @longitud_string(i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%16 = call i32 @longitud_string(i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %19
19: ; preds = %23, %0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%21 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %20)
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%26 = call i32 @longitud_string(i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %24, i32 %26)
br label %19
28: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@__const.main.string1 = [13 x i8] c"Hola a todos\00"
@.str = [12 x i8] c"cadena: %s\0A\00"
@.str.1 = [21 x i8] c"longitud cadena: %d\0A\00"
@.str.2 = [23 x i8] c"leer libros y revistas\00"
@.str.3 = [13 x i8] c"cadena2: %s\0A\00"
@.str.4 = [22 x i8] c"longitud cadena: %d\0A\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [21 x i8] c"Longitud de %s: %d \0A\00"
@str = [26 x i8] c"Lectura de STDIN: ---- # \00"
define i32 @main() {
%1 = alloca [13 x i8]
%2 = alloca [200 x i8]
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %4)
%8 = call i32 @longitud_string(i8* %4)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%12 = call i32 @longitud_string(i8* %5)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%15 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %0, %17
%18 = call i32 @longitud_string(i8* %6)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %6, i32 %18)
%20 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %17, label %22
22: ; preds = %17, %0
ret i32 0
}