#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*/ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
void merge_n_lines(int n, int max_length, char *delimiter) {
  char instring[500];
  int i, all_done = 0;
  while (!all_done) {
    for (i = 0; i < n; i++) {
      if (!get_line(instring, stdin)) {
        all_done = 1;
        break;
      }
      if (i > 0 && (strlen(instring) > max_length)) {
        printf("\n%s", instring);
        i = 0;
      } else {
        if (i == 0)
          printf("%s", instring);
        else
          printf("%s%s", delimiter, instring);
      }
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<merge_n_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x218(%rbp)
cmpl   $0x0,-0x218(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1168 <merge_n_lines+0x38>
jmp    1265 <merge_n_lines+0x135>
movl   $0x0,-0x214(%rbp)
mov    -0x214(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1252 <merge_n_lines+0x122>
lea    -0x210(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%eax
jne    11ae <merge_n_lines+0x7e>
movl   $0x1,-0x218(%rbp)
jmp    1252 <merge_n_lines+0x122>
cmpl   $0x0,-0x214(%rbp)
jle    11f4 <merge_n_lines+0xc4>
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x8(%rbp),%eax
jle    11f4 <merge_n_lines+0xc4>
lea    -0x210(%rbp),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x214(%rbp)
jmp    1239 <merge_n_lines+0x109>
cmpl   $0x0,-0x214(%rbp)
jne    121b <merge_n_lines+0xeb>
lea    -0x210(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1234 <merge_n_lines+0x104>
mov    -0x10(%rbp),%rsi
lea    -0x210(%rbp),%rdx
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1239 <merge_n_lines+0x109>
jmp    123e <merge_n_lines+0x10e>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    1172 <merge_n_lines+0x42>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    114f <merge_n_lines+0x1f>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_n_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f8,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
mov    0x2e88(%rip),%r12
mov    %rsp,%rbp
jmp    117a <merge_n_lines+0x3a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %ebx,%ebx
jle    1170 <merge_n_lines+0x30>
xor    %r13d,%r13d
jmp    11af <merge_n_lines+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
je     11dd <merge_n_lines+0x9d>
lea    0xe6b(%rip),%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r13d
cmp    %ebx,%r13d
jge    1170 <merge_n_lines+0x30>
mov    (%r12),%esi
mov    %rbp,%rdi
call   1040 <get_line@plt>
test   %eax,%eax
je     11f3 <merge_n_lines+0xb3>
test   %r13d,%r13d
jle    1190 <merge_n_lines+0x50>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmp    %r15d,%eax
jle    1192 <merge_n_lines+0x52>
xor    %r13d,%r13d
lea    0xe25(%rip),%rdi
jmp    11e7 <merge_n_lines+0xa7>
xor    %r13d,%r13d
lea    0xe1a(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11a6 <merge_n_lines+0x66>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"\0A%s\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @merge_n_lines(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [500 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %9
br label %10
10: ; preds = %51, %3
%11 = load i32, i32* %9
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %53
14: ; preds = %10
store i32 0, i32* %8
br label %15
15: ; preds = %48, %14
%16 = load i32, i32* %8
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %51
19: ; preds = %15
%20 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i32 @get_line(i8* %20, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 1, i32* %9
br label %51
25: ; preds = %19
%26 = load i32, i32* %8
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = load i32, i32* %5
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %34)
store i32 0, i32* %8
br label %47
36: ; preds = %28, %25
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %46
42: ; preds = %36
%43 = load i8*, i8** %6
%44 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %43, i8* %44)
br label %46
46: ; preds = %42, %39
br label %47
47: ; preds = %46, %33
br label %48
48: ; preds = %47
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %15
51: ; preds = %24, %15
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %10
53: ; preds = %10
ret void
}

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