#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 */
char **get_entire_array(int *);
int /*<<< orphan*/ printf(char *, ...);
void merge_n_groups(int number_groups, char *delimiter) {
  int x, y;
  int number_rows, array_len;
  char **entire_array = get_entire_array(&array_len);
  number_rows = array_len / number_groups;
  for (y = 0; y < number_rows; y++) {
    for (x = 0; x < number_groups; x++) {
      if (x == 0)
        printf("%s", entire_array[y + x * number_rows]);
      else
        printf("|%s", entire_array[y + x * number_rows]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<merge_n_groups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <get_entire_array@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x4(%rbp)
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f4 <merge_n_groups+0xd4>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d8 <merge_n_groups+0xb8>
cmpl   $0x0,-0x14(%rbp)
jne    11a0 <merge_n_groups+0x80>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%edx
imul   -0x1c(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <merge_n_groups+0xa5>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%edx
imul   -0x1c(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <merge_n_groups+0xaa>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <merge_n_groups+0x40>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114d <merge_n_groups+0x2d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_n_groups>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%rdi
call   1050 <get_entire_array@plt>
mov    %rax,0x10(%rsp)
mov    0xc(%rsp),%eax
cltd
mov    %ebx,0x8(%rsp)
idiv   %ebx
test   %eax,%eax
jle    1208 <merge_n_groups+0xd8>
mov    %eax,%ecx
mov    0x8(%rsp),%edx
mov    0x10(%rsp),%rax
lea    (%rax,%rcx,8),%rbp
mov    %rcx,0x20(%rsp)
lea    0x0(,%rcx,8),%r13
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x18(%rsp)
lea    0xe72(%rip),%rbx
xor    %r14d,%r14d
jmp    11b9 <merge_n_groups+0x89>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
add    $0x8,%rbp
cmp    0x20(%rsp),%r14
je     1208 <merge_n_groups+0xd8>
cmpl   $0x0,0x8(%rsp)
jle    11a0 <merge_n_groups+0x70>
mov    0x10(%rsp),%rax
mov    (%rax,%r14,8),%rsi
lea    0xe31(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x1,0x8(%rsp)
je     11a0 <merge_n_groups+0x70>
mov    0x18(%rsp),%r12
mov    %rbp,%r15
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    %r13,%r15
add    $0xffffffffffffffff,%r12
jne    11f0 <merge_n_groups+0xc0>
jmp    11a0 <merge_n_groups+0x70>
add    $0x28,%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 = [4 x i8] c"|%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @merge_n_groups(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = call i8** @get_entire_array(i32* %8)
store i8** %10, i8*** %9
%11 = load i32, i32* %8
%12 = load i32, i32* %3
%13 = sdiv i32 %11, %12
store i32 %13, i32* %7
store i32 0, i32* %6
br label %14
14: ; preds = %54, %2
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %57
18: ; preds = %14
store i32 0, i32* %5
br label %19
19: ; preds = %49, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %52
23: ; preds = %19
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load i8**, i8*** %9
%28 = load i32, i32* %6
%29 = load i32, i32* %5
%30 = load i32, i32* %7
%31 = mul nsw i32 %29, %30
%32 = add nsw i32 %28, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %27, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %35)
br label %48
37: ; preds = %23
%38 = load i8**, i8*** %9
%39 = load i32, i32* %6
%40 = load i32, i32* %5
%41 = load i32, i32* %7
%42 = mul nsw i32 %40, %41
%43 = add nsw i32 %39, %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %38, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %37, %26
br label %49
49: ; preds = %48
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %19
52: ; preds = %19
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %52
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %14
57: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"|%s\00"
define void @merge_n_groups(i32 %0, i8* nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i8** @get_entire_array(i32* %3)
%6 = load i32, i32* %3
%7 = sdiv i32 %6, %0
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %34
9: ; preds = %2
%10 = icmp sgt i32 %0, 0
%11 = zext i32 %7 to i64
%12 = zext i32 %7 to i64
%13 = zext i32 %0 to i64
%14 = icmp eq i32 %0, 1
br label %15
15: ; preds = %9, %30
%16 = phi i64 [ 0, %9 ], [ %32, %30 ]
br i1 %10, label %17, label %30
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %5, i64 %16
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
br i1 %14, label %30, label %21
21: ; preds = %17, %21
%22 = phi i64 [ %28, %21 ], [ 1, %17 ]
%23 = mul nsw i64 %22, %11
%24 = add nuw nsw i64 %23, %16
%25 = getelementptr inbounds i8*, i8** %5, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = add nuw nsw i64 %22, 1
%29 = icmp eq i64 %28, %13
br i1 %29, label %30, label %21
30: ; preds = %21, %17, %15
%31 = call i32 @putchar(i32 10)
%32 = add nuw nsw i64 %16, 1
%33 = icmp eq i64 %32, %12
br i1 %33, label %34, label %15
34: ; preds = %30, %2
ret void
}