#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 ceil(double);
int floor(double);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
double sqrt(int);
int strlen(char *);
int main() {
  char *s = (char *)malloc(10240 * sizeof(char));
  scanf("%s", s);
  int len = strlen(s);
  double sq = sqrt(len);
  int rows = floor(sq);
  int cols = ceil(sq);
  if (rows * cols < len) {
    rows++;
  }
  int index;
  for (int i = 0; i < cols; i++) {
    for (int j = 0; j < rows; j++) {
      index = (j * cols) + i;
      if (index < len) {
        printf("%c", s[index]);
      }
    }
    printf(" ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x2800,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1090 <floor@plt>
mov    %eax,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <ceil@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e9 <main+0x79>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1271 <main+0x101>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1255 <main+0xe5>
mov    -0x34(%rbp),%eax
imul   -0x28(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1242 <main+0xd2>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1247 <main+0xd7>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1203 <main+0x93>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11f0 <main+0x80>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x2800,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
lea    0xe6e(%rip),%rdi
mov    %rax,%rsi
call   1070 <scanf@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1080 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
call   1090 <floor@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1040 <ceil@plt>
mov    %eax,%edx
imul   %ebx,%edx
xor    %ecx,%ecx
cmp    %r14d,%edx
setl   %dl
test   %eax,%eax
jle    123a <main+0xca>
mov    %ebx,%esi
mov    %dl,%cl
add    %ecx,%esi
mov    %eax,%ebp
movslq %r14d,%rbx
mov    %esi,0x8(%rsp)
mov    %esi,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
jmp    1203 <main+0x93>
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
cmp    %rbp,%r15
je     123a <main+0xca>
mov    0x10(%rsp),%r14
mov    %r15,%r13
cmpl   $0x0,0x8(%rsp)
jg     1229 <main+0xb9>
jmp    11f0 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %rbp,%r13
add    $0xffffffffffffffff,%r14
je     11f0 <main+0x80>
cmp    %rbx,%r13
jge    1220 <main+0xb0>
movsbl (%r12,%r13,1),%edi
call   1030 <putchar@plt>
jmp    1220 <main+0xb0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i64 @malloc(i32 10240)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = call double @sqrt(i32 %16)
store double %17, double* %4
%18 = load double, double* %4
%19 = call i32 @floor(double %18)
store i32 %19, i32* %5
%20 = load double, double* %4
%21 = call i32 @ceil(double %20)
store i32 %21, i32* %6
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = mul nsw i32 %22, %23
%25 = load i32, i32* %3
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %0
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %30
30: ; preds = %27, %0
store i32 0, i32* %8
br label %31
31: ; preds = %63, %30
%32 = load i32, i32* %8
%33 = load i32, i32* %6
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %66
35: ; preds = %31
store i32 0, i32* %9
br label %36
36: ; preds = %58, %35
%37 = load i32, i32* %9
%38 = load i32, i32* %5
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %61
40: ; preds = %36
%41 = load i32, i32* %9
%42 = load i32, i32* %6
%43 = mul nsw i32 %41, %42
%44 = load i32, i32* %8
%45 = add nsw i32 %43, %44
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = load i32, i32* %3
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %57
49: ; preds = %40
%50 = load i8*, i8** %2
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %49, %40
br label %58
58: ; preds = %57
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
br label %36
61: ; preds = %36
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %63
63: ; preds = %61
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %31
66: ; preds = %31
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 10240)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = tail call i32 @strlen(i8* %2)
%5 = tail call double @sqrt(i32 %4)
%6 = tail call i32 @floor(double %5)
%7 = tail call i32 @ceil(double %5)
%8 = mul nsw i32 %7, %6
%9 = icmp slt i32 %8, %4
%10 = zext i1 %9 to i32
%11 = add i32 %6, %10
%12 = icmp sgt i32 %7, 0
br i1 %12, label %13, label %21
13: ; preds = %0
%14 = icmp sgt i32 %11, 0
%15 = zext i32 %7 to i64
%16 = sext i32 %4 to i64
%17 = zext i32 %7 to i64
%18 = zext i32 %11 to i64
br label %19
19: ; preds = %13, %22
%20 = phi i64 [ 0, %13 ], [ %24, %22 ]
br i1 %14, label %26, label %22
21: ; preds = %22, %0
ret i32 0
22: ; preds = %36, %19
%23 = tail call i32 @putchar(i32 32)
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, %17
br i1 %25, label %21, label %19
26: ; preds = %19, %36
%27 = phi i64 [ %37, %36 ], [ 0, %19 ]
%28 = mul nsw i64 %27, %15
%29 = add nuw nsw i64 %28, %20
%30 = icmp slt i64 %29, %16
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = getelementptr inbounds i8, i8* %2, i64 %29
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = tail call i32 @putchar(i32 %34)
br label %36
36: ; preds = %26, %31
%37 = add nuw nsw i64 %27, 1
%38 = icmp eq i64 %37, %18
br i1 %38, label %22, label %26
}