#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(int argc, char *argv[]) {
  char s[255];
  printf("Nhap vao mot chuoi\n");
  gets(s);
  int i;
  for (i = 0; s[i] != 0; i++)
    ;
  printf("Length of string is %d", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <gets@plt>
movl   $0x0,-0x114(%rbp)
movslq -0x114(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     118e <main+0x6e>
jmp    117a <main+0x5a>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    115d <main+0x3d>
mov    -0x114(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <gets@plt>
mov    $0xffffffff,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%esi
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1160 <main+0x30>
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str.1 = [23 x i8] c"Length of string is %d\00"
@str = [19 x i8] c"Nhap vao mot chuoi\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%6 = call i32 @gets(i8* %4)
br label %7
7: ; preds = %7, %2
%8 = phi i64 [ %12, %7 ], [ 0, %2 ]
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
%12 = add nuw i64 %8, 1
br i1 %11, label %13, label %7
13: ; preds = %7
%14 = trunc i64 %8 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %14)
ret i32 0
}