#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, char *);
int sscanf(char *, char *, char **);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
main() {
  char test[] = "This is the test string";
  char temp[100];
  int length;
  char *sp;
  while (sscanf(test, "%s", &temp) == 1) {
    printf("%d: %s\n", length = strlen(temp), temp);
    sp = strstr(test, temp) + length;
    strcpy(test, sp);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe97(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe94(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xe83(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1200 <main+0xb0>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
mov    %esi,-0x94(%rbp)
lea    -0x90(%rbp),%rdx
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1070 <strstr@plt>
movslq -0x94(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0xa0(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1183 <main+0x33>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x676e6972747320,%rax
mov    %rax,0x10(%rsp)
lea    0xe98(%rip),%rsi
mov    %rsp,%rdi
lea    0x20(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11f3 <main+0xa3>
lea    0x20(%rsp),%rbx
lea    0xe7d(%rip),%r14
mov    %rsp,%r15
lea    0xe70(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <strstr@plt>
movslq %ebp,%rsi
add    %rax,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11b0 <main+0x60>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.test = [24 x i8] c"This is the test string\00"
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"%d: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [24 x i8]
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast [24 x i8]* %2 to i8*
br label %7
7: ; preds = %12, %0
%8 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%9 = bitcast [100 x i8]* %3 to i8**
%10 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %26
12: ; preds = %7
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %4
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* %15)
%17 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%19 = call i8* @strstr(i8* %17, i8* %18)
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8* %22, i8** %5
%23 = getelementptr inbounds [24 x i8], [24 x i8]* %2, i64 0, i64 0
%24 = load i8*, i8** %5
%25 = call i32 @strcpy(i8* %23, i8* %24)
br label %7
26: ; preds = %7
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@__const.main.test = [24 x i8] c"This is the test string\00"
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"%d: %s\0A\00"
define i32 @main() {
%1 = alloca [24 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = bitcast [100 x i8]* %2 to i8**
%6 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %17
8: ; preds = %0, %8
%9 = call i32 @strlen(i8* %4)
%10 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %4)
%11 = call i8* @strstr(i8* %3, i8* %4)
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = call i32 @strcpy(i8* %3, i8* %13)
%15 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5)
%16 = icmp eq i32 %15, 1
br i1 %16, label %8, label %17
17: ; preds = %8, %0
ret i32 0
}