#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 */
scalar_t__ EOF;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ izpis(char *, int);
scalar_t__ malloc(int);
scalar_t__ scanf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int main() {
  const int MAX = 100000;
  int poravnava;
  scanf("%d", &poravnava);
  char *temp = (char *)malloc(sizeof(char) * MAX);
  char *out = (char *)malloc(sizeof(char) * MAX);
  while (scanf("%s", temp) != EOF) {
    if (strlen(out) + strlen(temp) > poravnava) {
      izpis(out, poravnava);
      free(out);
      char *out = (char *)malloc(sizeof(char) * MAX);
      out[0] = '\0';
    }
    strcat(out, temp);
    strcat(out, " ");
  }
  izpis(out, poravnava);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x186a0,-0x8(%rbp)
lea    0xe83(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    $0x186a0,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x186a0,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%rax
je     1237 <main+0xd7>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
cmp    -0xc(%rbp),%eax
jle    1215 <main+0xb5>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <izpis@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x186a0,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1080 <strcat@plt>
jmp    11a4 <main+0x44>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <izpis@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    $0x186a0,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x186a0,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe64(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x2e38(%rip),%r13
cmp    0x0(%r13),%rax
jne    11d3 <main+0x73>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <izpis@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2c(%rip),%r15
lea    0xe22(%rip),%r12
jmp    1219 <main+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmp    0x0(%r13),%rax
je     11b6 <main+0x56>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %ebp,%eax
mov    0x4(%rsp),%esi
cmp    %esi,%eax
jle    11f0 <main+0x90>
mov    %rbx,%rdi
call   1040 <izpis@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x186a0,%edi
call   1060 <malloc@plt>
movb   $0x0,(%rax)
jmp    11f0 <main+0x90>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
store i32 100000, i32* %2
%7 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = call i64 @malloc(i32 100000)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = call i64 @malloc(i32 100000)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
br label %12
12: ; preds = %35, %0
%13 = load i8*, i8** %4
%14 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i64, i64* @EOF
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %41
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %19, %21
%23 = load i32, i32* %3
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %17
%26 = load i8*, i8** %5
%27 = load i32, i32* %3
%28 = call i32 @izpis(i8* %26, i32 %27)
%29 = load i8*, i8** %5
%30 = call i32 @free(i8* %29)
%31 = call i64 @malloc(i32 100000)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 0
store i8 0, i8* %34
br label %35
35: ; preds = %25, %17
%36 = load i8*, i8** %5
%37 = load i8*, i8** %4
%38 = call i32 @strcat(i8* %36, i8* %37)
%39 = load i8*, i8** %5
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %12
41: ; preds = %12
%42 = load i8*, i8** %5
%43 = load i32, i32* %3
%44 = call i32 @izpis(i8* %42, i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = call i64 @malloc(i32 100000)
%5 = inttoptr i64 %4 to i8*
%6 = call i64 @malloc(i32 100000)
%7 = inttoptr i64 %6 to i8*
%8 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = load i64, i64* @EOF
%10 = icmp eq i64 %8, %9
br i1 %10, label %28, label %11
11: ; preds = %0, %22
%12 = call i32 @strlen(i8* %7)
%13 = call i32 @strlen(i8* %5)
%14 = add nsw i32 %13, %12
%15 = load i32, i32* %1
%16 = icmp sgt i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = call i32 @izpis(i8* %7, i32 %15)
%19 = call i32 @free(i8* %7)
%20 = call i64 @malloc(i32 100000)
%21 = inttoptr i64 %20 to i8*
store i8 0, i8* %21
br label %22
22: ; preds = %17, %11
%23 = call i32 @strcat(i8* %7, i8* %5)
%24 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %11
28: ; preds = %22, %0
%29 = load i32, i32* %1
%30 = call i32 @izpis(i8* %7, i32 %29)
ret i32 0
}