#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
main() {
  char str[100];
  int i;
  printf("enter string: ");
  scanf("%[^\n]s", str);
  printf("len=%d\n", strlen(str));
  str[3] = 0;
  printf("len=%d in string %s\n", strlen(str + 4), str + 4);
  printf("len=%d in string %s\n", strlen(str + 1), str + 1);
  printf("len=%d in string %s\n", strlen(str + 3), str + 3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xebb(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movb   $0x0,-0x6d(%rbp)
lea    -0x70(%rbp),%rdi
add    $0x4,%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x70(%rbp),%rdx
add    $0x4,%rdx
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x70(%rbp),%rdx
add    $0x1,%rdx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
add    $0x3,%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x70(%rbp),%rdx
add    $0x3,%rdx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec1(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xeae(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x3(%rsp),%r14
movb   $0x0,0x3(%rsp)
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xe8f(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"enter string: \00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [8 x i8] c"len=%d\0A\00"
@.str.3 = [21 x i8] c"len=%d in string %s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
store i8 0, i8* %9
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%11 = getelementptr inbounds i8, i8* %10, i64 4
%12 = call i32 @strlen(i8* %11)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%14 = getelementptr inbounds i8, i8* %13, i64 4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %12, i8* %14)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = call i32 @strlen(i8* %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %18, i8* %20)
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 3
%24 = call i32 @strlen(i8* %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%26 = getelementptr inbounds i8, i8* %25, i64 3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"enter string: \00"
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@.str.2 = [8 x i8] c"len=%d\0A\00"
@.str.3 = [21 x i8] c"len=%d in string %s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32 @strlen(i8* %2)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
store i8 0, i8* %7
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
%9 = call i32 @strlen(i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %9, i8* %8)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%12 = call i32 @strlen(i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %12, i8* %11)
%14 = call i32 @strlen(i8* %7)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %14, i8* %7)
ret i32 0
}