#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 /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
double sqrt(int);
scalar_t__ strlen(char *);
int encryption(void) {
  char *message = malloc(sizeof(char) * (81 + 1));
  scanf("%s", message);
  int messageLength = (int)strlen(message);
  double root = sqrt(messageLength);
  int width = root;
  int height = ceil(root);
  if (width * height < messageLength) {
    width++;
  }
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      int messageIndex = height * j + i;
      if (messageIndex < messageLength) {
        printf("%c", message[messageIndex]);
      }
    }
    printf(" ");
  }
  free(message);
  return 0;
}


x86 assembly (clang, -O0):
<encryption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x52,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1090 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <ceil@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dd <encryption+0x6d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1265 <encryption+0xf5>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1249 <encryption+0xd9>
mov    -0x20(%rbp),%eax
imul   -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1236 <encryption+0xc6>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    123b <encryption+0xcb>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11f7 <encryption+0x87>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e4 <encryption+0x74>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encryption>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x52,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
lea    0xe6e(%rip),%rdi
mov    %rax,%rsi
call   1080 <scanf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %rax,%r14
mov    %r14d,%edi
call   1090 <sqrt@plt>
cvttsd2si %xmm0,%ebx
call   1050 <ceil@plt>
mov    %eax,%ecx
imul   %ebx,%ecx
cmp    %r14d,%ecx
setl   %cl
test   %eax,%eax
jle    122a <encryption+0xba>
xor    %edx,%edx
mov    %cl,%dl
add    %ebx,%edx
mov    %eax,%ebp
movslq %r14d,%rbx
mov    %edx,0xc(%rsp)
mov    %edx,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
jmp    11f3 <encryption+0x83>
mov    $0x20,%edi
call   1040 <putchar@plt>
add    $0x1,%r15
cmp    %rbp,%r15
je     122a <encryption+0xba>
mov    0x10(%rsp),%r14
mov    %r15,%r13
cmpl   $0x0,0xc(%rsp)
jg     1219 <encryption+0xa9>
jmp    11e0 <encryption+0x70>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %rbp,%r13
add    $0xffffffffffffffff,%r14
je     11e0 <encryption+0x70>
cmp    %rbx,%r13
jge    1210 <encryption+0xa0>
movsbl (%r12,%r13,1),%edi
call   1040 <putchar@plt>
jmp    1210 <encryption+0xa0>
mov    %r12,%rdi
call   1030 <free@plt>
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 @encryption() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = call i8* @malloc(i32 82)
store i8* %9, i8** %1
%10 = load i8*, i8** %1
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %1
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = call double @sqrt(i32 %15)
store double %16, double* %3
%17 = load double, double* %3
%18 = fptosi double %17 to i32
store i32 %18, i32* %4
%19 = load double, double* %3
%20 = call i32 @ceil(double %19)
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = mul nsw i32 %21, %22
%24 = load i32, i32* %2
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %0
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %29
29: ; preds = %26, %0
store i32 0, i32* %6
br label %30
30: ; preds = %62, %29
%31 = load i32, i32* %6
%32 = load i32, i32* %5
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %65
34: ; preds = %30
store i32 0, i32* %7
br label %35
35: ; preds = %57, %34
%36 = load i32, i32* %7
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %60
39: ; preds = %35
%40 = load i32, i32* %5
%41 = load i32, i32* %7
%42 = mul nsw i32 %40, %41
%43 = load i32, i32* %6
%44 = add nsw i32 %42, %43
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = load i32, i32* %2
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %56
48: ; preds = %39
%49 = load i8*, i8** %1
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %48, %39
br label %57
57: ; preds = %56
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %35
60: ; preds = %35
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %60
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %30
65: ; preds = %30
%66 = load i8*, i8** %1
%67 = call i32 @free(i8* %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @encryption() {
%1 = tail call dereferenceable_or_null(82) i8* @malloc(i32 82)
%2 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = tail call double @sqrt(i32 %4)
%6 = fptosi double %5 to i32
%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 %10, %6
%12 = icmp sgt i32 %7, 0
br i1 %12, label %13, label %22
13: ; preds = %0
%14 = icmp sgt i32 %11, 0
%15 = zext i32 %7 to i64
%16 = shl i64 %3, 32
%17 = ashr exact i64 %16, 32
%18 = zext i32 %7 to i64
%19 = zext i32 %11 to i64
br label %20
20: ; preds = %13, %24
%21 = phi i64 [ 0, %13 ], [ %26, %24 ]
br i1 %14, label %28, label %24
22: ; preds = %24, %0
%23 = tail call i32 @free(i8* %1)
ret i32 0
24: ; preds = %38, %20
%25 = tail call i32 @putchar(i32 32)
%26 = add nuw nsw i64 %21, 1
%27 = icmp eq i64 %26, %18
br i1 %27, label %22, label %20
28: ; preds = %20, %38
%29 = phi i64 [ %39, %38 ], [ 0, %20 ]
%30 = mul nsw i64 %29, %15
%31 = add nuw nsw i64 %30, %21
%32 = icmp slt i64 %31, %17
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = getelementptr inbounds i8, i8* %1, i64 %31
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = tail call i32 @putchar(i32 %36)
br label %38
38: ; preds = %33, %28
%39 = add nuw nsw i64 %29, 1
%40 = icmp eq i64 %39, %19
br i1 %40, label %24, label %28
}