#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*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverse_string(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  int num_grp, unit;
  char line[128];
  char *ptr;
  while (fgets(line, 128, stdin) != NULL && line[0] != '0') {
    sscanf(line, "%d %s\n", &num_grp, line);
    unit = strlen(line) / num_grp;
    for (ptr = &line[0]; *ptr != '\0'; ptr += unit) {
      reverse_string(ptr, ptr + unit - 1);
    }
    printf("%s\n", line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x99(%rbp)
je     11a4 <main+0x54>
movsbl -0x90(%rbp),%eax
cmp    $0x30,%eax
setne  %al
mov    %al,-0x99(%rbp)
mov    -0x99(%rbp),%al
test   $0x1,%al
jne    11b7 <main+0x67>
jmp    125b <main+0x10b>
lea    -0x90(%rbp),%rdi
lea    -0x90(%rbp),%rcx
lea    0xe34(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1070 <sscanf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
cltd
idivl  -0x8(%rbp)
mov    %eax,-0xc(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1243 <main+0xf3>
mov    -0x98(%rbp),%rdi
mov    -0x98(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <reverse_string@plt>
mov    -0xc(%rbp),%ecx
mov    -0x98(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x98(%rbp)
jmp    11f6 <main+0xa6>
lea    -0x90(%rbp),%rsi
lea    0xdb2(%rip),%rdi
call   1050 <printf@plt>
jmp    1162 <main+0x12>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    $0x80,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     121a <main+0xca>
cmpb   $0x30,0x10(%rsp)
je     121a <main+0xca>
lea    0xc(%rsp),%r15
lea    0xe67(%rip),%r12
nopl   0x0(%rax)
mov    %r13,%rdi
lea    0xe56(%rip),%rsi
mov    %r15,%rdx
mov    %r13,%rcx
call   1070 <sscanf@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
cmpb   $0x0,0x10(%rsp)
je     11ed <main+0x9d>
cltd
idivl  0xc(%rsp)
movslq %eax,%rbp
mov    %r13,%rbx
nop
lea    (%rbx,%rbp,1),%r14
lea    (%rbx,%rbp,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %rbx,%rdi
call   1030 <reverse_string@plt>
cmpb   $0x0,(%rbx,%rbp,1)
mov    %r14,%rbx
jne    11d0 <main+0x80>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    $0x80,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     121a <main+0xca>
cmpb   $0x30,0x10(%rsp)
jne    11a0 <main+0x50>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [7 x i8] c"%d %s\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca i8*
store i32 0, i32* %1
br label %6
6: ; preds = %45, %0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32* @fgets(i8* %7, i32 128, i32 %8)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 48
br label %16
16: ; preds = %11, %6
%17 = phi i1 [ false, %6 ], [ %15, %11 ]
br i1 %17, label %18, label %48
18: ; preds = %16
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%21 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %2, i8* %20)
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = load i32, i32* %2
%25 = sdiv i32 %23, %24
store i32 %25, i32* %3
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
store i8* %26, i8** %5
br label %27
27: ; preds = %40, %18
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = load i8*, i8** %5
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = getelementptr inbounds i8, i8* %37, i64 -1
%39 = call i32 @reverse_string(i8* %33, i8* %38)
br label %40
40: ; preds = %32
%41 = load i32, i32* %3
%42 = load i8*, i8** %5
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %5
br label %27
45: ; preds = %27
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %46)
br label %6
48: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [7 x i8] c"%d %s\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %4, i32 128, i32 %5)
%7 = icmp ne i32* %6, null
%8 = load i8, i8* %4
%9 = icmp ne i8 %8, 48
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %35
11: ; preds = %0, %27
%12 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %1, i8* %4)
%13 = call i32 @strlen(i8* %4)
%14 = load i8, i8* %4
%15 = icmp eq i8 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %11
%17 = load i32, i32* %1
%18 = sdiv i32 %13, %17
%19 = sext i32 %18 to i64
br label %20
20: ; preds = %16, %20
%21 = phi i8* [ %4, %16 ], [ %22, %20 ]
%22 = getelementptr inbounds i8, i8* %21, i64 %19
%23 = getelementptr inbounds i8, i8* %22, i64 -1
%24 = call i32 @reverse_string(i8* %21, i8* %23)
%25 = load i8, i8* %22
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %20
27: ; preds = %20, %11
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%29 = load i32, i32* @stdin
%30 = call i32* @fgets(i8* %4, i32 128, i32 %29)
%31 = icmp ne i32* %30, null
%32 = load i8, i8* %4
%33 = icmp ne i8 %32, 48
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %11, label %35
35: ; preds = %27, %0
ret i32 0
}