#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 EXIT_SUCCESS;
int /*<<< orphan*/ *gets(char *);
int /*<<< orphan*/ printf(char *, char *);
int read_column_numbers(int *, int);
int /*<<< orphan*/ rearrange(char *, char *, int, int *);
int main(void) {
  int n_columns;
  int columns[20];
  char input[1000];
  char output[1000];
  n_columns = read_column_numbers(columns, 20);
  while (gets(input) != NULL) {
    printf("Original input : %s\n", input);
    rearrange(output, input, n_columns, columns);
    printf("Rearranged line: %s\n", output);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x14,%esi
call   1060 <read_column_numbers@plt>
mov    %eax,-0x8(%rbp)
lea    -0x450(%rbp),%rdi
call   1050 <gets@plt>
cmp    $0x0,%rax
je     11be <main+0x7e>
lea    -0x450(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
lea    -0x840(%rbp),%rdi
lea    -0x450(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    -0x60(%rbp),%rcx
call   1040 <rearrange@plt>
lea    -0x840(%rbp),%rsi
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
jmp    1163 <main+0x23>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    %rsp,%rdi
mov    $0x14,%esi
call   1060 <read_column_numbers@plt>
mov    %eax,%r15d
lea    0x50(%rsp),%rdi
call   1050 <gets@plt>
test   %rax,%rax
je     11c4 <main+0x84>
lea    0xe89(%rip),%r14
lea    0x50(%rsp),%rbx
lea    0x440(%rsp),%rbp
mov    %rsp,%r12
lea    0xe87(%rip),%r13
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r12,%rcx
call   1040 <rearrange@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
test   %rax,%rax
jne    1190 <main+0x50>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Original input : %s\0A\00"
@.str.1 = [21 x i8] c"Rearranged line: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i32]
%4 = alloca [1000 x i8]
%5 = alloca [1000 x i8]
store i32 0, i32* %1
%6 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%7 = call i32 @read_column_numbers(i32* %6, i32 20)
store i32 %7, i32* %2
br label %8
8: ; preds = %12, %0
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%10 = call i32* @gets(i8* %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%17 = load i32, i32* %2
%18 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%19 = call i32 @rearrange(i8* %15, i8* %16, i32 %17, i32* %18)
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %8
22: ; preds = %8
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}

LLVM IR (-O2):
@.str = [21 x i8] c"Original input : %s\0A\00"
@.str.1 = [21 x i8] c"Rearranged line: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = bitcast [20 x i32]* %1 to i8*
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%8 = call i32 @read_column_numbers(i32* %7, i32 20)
%9 = call i32* @gets(i8* %5)
%10 = icmp eq i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %0, %11
%12 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %5)
%13 = call i32 @rearrange(i8* %6, i8* %5, i32 %8, i32* %7)
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%15 = call i32* @gets(i8* %5)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %11
17: ; preds = %11, %0
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}