#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 *, char *, int);
int main() {
  char string[30];
  int i = 0, cont = 0;
  gets(string);
  while (string[i] != '\0') {
    cont++;
    i++;
  }
  printf("tamanho de (%s) = %d", string, cont);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <gets@plt>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     116f <main+0x4f>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1146 <main+0x26>
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%edx
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    %rsp,%rdi
call   1040 <gets@plt>
cmpb   $0x0,(%rsp)
je     114d <main+0x2d>
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x0,0x1(%rsp,%rdx,1)
lea    0x1(%rdx),%rdx
jne    1140 <main+0x20>
jmp    114f <main+0x2f>
xor    %edx,%edx
lea    0xeaa(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"tamanho de (%s) = %d\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%3 = call i32 @gets(i8* %2)
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %8, %6 ], [ 0, %0 ]
%8 = add nuw nsw i64 %7, 1
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %6
12: ; preds = %6
%13 = trunc i64 %8 to i32
br label %14
14: ; preds = %12, %0
%15 = phi i32 [ 0, %0 ], [ %13, %12 ]
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %15)
ret i32 0
}