#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char buf[30] = {};
  int i = 0, j = 0;
  if (argc < 2) {
    printf("Usage: ./tornado <\"string\">");
    return -1;
  }
  if (strlen(argv[1]) > 30) {
    printf("Text to long\n");
    return -2;
  }
  memset(buf, 0x20, 30);
  memcpy(buf, argv[1], strlen(argv[1]));
  printf("%s\n", buf);
  int k = 0;
  while (k++ < 300) {
    do {
      printf("%c", buf[i++ % 30]);
    } while ((i % 30) != (j % 30));
    ++j;
    i = j;
    puts("");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1060 <memset@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a8 <main+0x58>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12be <main+0x16e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x1e,%eax
jle    11d8 <main+0x88>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12be <main+0x16e>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
mov    $0x1e,%edx
call   1060 <memset@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
lea    -0x30(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3c(%rbp)
cmp    $0x12c,%eax
jge    12be <main+0x16e>
jmp    124f <main+0xff>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
mov    $0x1e,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movsbl -0x30(%rbp,%rax,1),%esi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
mov    $0x1e,%ecx
cltd
idiv   %ecx
mov    %edx,-0x54(%rbp)
mov    -0x38(%rbp),%eax
mov    $0x1e,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x54(%rbp),%edx
cmp    %eax,%edx
jne    124f <main+0xff>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    0xd75(%rip),%rdi
call   1030 <puts@plt>
jmp    1234 <main+0xe4>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x1e(%rsp)
movaps %xmm0,0x10(%rsp)
cmp    $0x1,%edi
jg     1198 <main+0x38>
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    128c <main+0x12c>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <strlen@plt>
cmp    $0x1f,%eax
jl     11bf <main+0x5f>
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
mov    $0xfffffffe,%eax
jmp    128c <main+0x12c>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x20,%esi
mov    $0x1e,%edx
call   1070 <memset@plt>
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <memcpy@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %r15d,%r15d
mov    $0x88888889,%r12d
movabs $0x8888888888888889,%r13
88 88 88
nopw   0x0(%rax,%rax,1)
mov    %r15d,%eax
imul   %r12,%rax
shr    $0x24,%rax
imul   $0xffffffe2,%eax,%ebp
mov    %r15,%rbx
mov    %r14,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rax
mul    %r13
shr    $0x4,%rdx
imul   $0xffffffffffffffe2,%rdx,%rax
add    $0x1,%rbx
movsbl (%r14,%rax,1),%edi
call   1030 <putchar@plt>
add    $0x1,%r14
add    $0xffffffff,%ebp
mov    %ebx,%eax
imul   %r12,%rax
shr    $0x24,%rax
mov    %eax,%ecx
shl    $0x5,%ecx
sub    %eax,%ecx
sub    %eax,%ecx
add    %ebp,%ecx
jne    1230 <main+0xd0>
add    $0x1,%r15
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%r14
add    $0x1,%r14
cmp    $0x12c,%r15d
jne    1210 <main+0xb0>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Usage: ./tornado <\22string\22>\00"
@.str.1 = [14 x i8] c"Text to long\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [30 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [30 x i8]* %6 to i8*
store i32 0, i32* %7
store i32 0, i32* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %62
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
%20 = icmp sgt i32 %19, 30
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %62
23: ; preds = %15
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 32, i32 30)
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @memcpy(i8* %26, i8* %29, i32 %33)
%35 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %35)
store i32 0, i32* %9
br label %37
37: ; preds = %57, %23
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
%40 = icmp slt i32 %38, 300
br i1 %40, label %41, label %62
41: ; preds = %37
br label %42
42: ; preds = %51, %41
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
%45 = srem i32 %43, 30
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %42
%52 = load i32, i32* %7
%53 = srem i32 %52, 30
%54 = load i32, i32* %8
%55 = srem i32 %54, 30
%56 = icmp ne i32 %53, %55
br i1 %56, label %42, label %57
57: ; preds = %51
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
%60 = load i32, i32* %8
store i32 %60, i32* %7
%61 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
br label %37
62: ; preds = %13, %21, %37
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [28 x i8] c"Usage: ./tornado <\22string\22>\00"
@str = [13 x i8] c"Text to long\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [30 x i8]
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %39
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strlen(i8* %10)
%12 = icmp sgt i32 %11, 30
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %39
15: ; preds = %8
%16 = call i32 @memset(i8* %4, i32 32, i32 30)
%17 = load i8*, i8** %9
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @memcpy(i8* %4, i8* %17, i32 %18)
%20 = call i32 @puts(i8* %4)
br label %21
21: ; preds = %15, %35
%22 = phi i32 [ 0, %15 ], [ %36, %35 ]
%23 = urem i32 %22, 30
br label %24
24: ; preds = %21, %24
%25 = phi i32 [ %26, %24 ], [ %22, %21 ]
%26 = add nuw nsw i32 %25, 1
%27 = urem i32 %25, 30
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 @putchar(i32 %31)
%33 = urem i32 %26, 30
%34 = icmp eq i32 %33, %23
br i1 %34, label %35, label %24
35: ; preds = %24
%36 = add nuw nsw i32 %22, 1
%37 = call i32 @putchar(i32 10)
%38 = icmp eq i32 %36, 300
br i1 %38, label %39, label %21
39: ; preds = %35, %13, %6
%40 = phi i32 [ -1, %6 ], [ -2, %13 ], [ 0, %35 ]
ret i32 %40
}