#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*/ demo_strtok();
int /*<<< orphan*/ demo_substr();
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(void) {
  char str2[10];
  char str1[10];
  int i;
  for (i = 0; i < 10; ++i) {
    str1[i] = 'a';
    str2[i] = 'z';
  }
  str2[10 - 1] = '\0';
  printf("str1 = %s \n", str1);
  printf("str2 = %s \n", str2);
  int len1 = strlen(str1);
  int len2 = strlen(str2);
  printf("len1 = %d \n", len1);
  printf("len2 = %d \n", len2);
  printf("\n\n\n");
  demo_substr();
  printf("\n\n\n");
  demo_strtok();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    1180 <main+0x40>
movslq -0x1c(%rbp),%rax
movb   $0x61,-0x18(%rbp,%rax,1)
movslq -0x1c(%rbp),%rax
movb   $0x7a,-0xe(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <main+0x16>
movb   $0x0,-0x5(%rbp)
lea    -0x18(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <demo_substr@plt>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <demo_strtok@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movabs $0x6161616161616161,%rax
61 61 61
mov    %rax,(%rsp)
movw   $0x6161,0x8(%rsp)
movabs $0x7a7a7a7a7a7a7a7a,%rax
7a 7a 7a
mov    %rax,0x10(%rsp)
movw   $0x7a,0x18(%rsp)
lea    0xe76(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe6e(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe50(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe48(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <demo_substr@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <demo_strtok@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"str1 = %s \0A\00"
@.str.1 = [12 x i8] c"str2 = %s \0A\00"
@.str.2 = [12 x i8] c"len1 = %d \0A\00"
@.str.3 = [12 x i8] c"len2 = %d \0A\00"
@.str.4 = [4 x i8] c"\0A\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %12
store i8 97, i8* %13
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %15
store i8 122, i8* %16
br label %17
17: ; preds = %10
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %7
20: ; preds = %7
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 9
store i8 0, i8* %21
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %5
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
store i32 %29, i32* %6
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 (...) @demo_substr()
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 (...) @demo_strtok()
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"str1 = %s \0A\00"
@.str.1 = [12 x i8] c"str2 = %s \0A\00"
@.str.2 = [12 x i8] c"len1 = %d \0A\00"
@.str.3 = [12 x i8] c"len2 = %d \0A\00"
@str.5 = [3 x i8] c"\0A\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 9
store i8 0, i8* %7
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %6)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%10 = call i32 @strlen(i8* %6)
%11 = call i32 @strlen(i8* %5)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
%15 = call i32 (...) @demo_substr()
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
%17 = call i32 (...) @demo_strtok()
ret i32 0
}