#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*/ gets(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, n;
  char *str;
  scanf("%d\n", &n);
  while (n != 0) {
    str = (char *)malloc(sizeof(char) * n);
    gets(str);
    for (i = n - 1; i >= 0; --i) {
      printf("%c", str[i]);
    }
    printf("\n");
    scanf("%d\n", &n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
je     11e3 <main+0xa3>
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <gets@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11c0 <main+0x80>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    118e <main+0x4e>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2b(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
jmp    115f <main+0x1f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
je     11c9 <main+0x89>
lea    0xe98(%rip),%r14
lea    0x4(%rsp),%r15
jmp    118d <main+0x4d>
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
je     11c9 <main+0x89>
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <gets@plt>
mov    0x4(%rsp),%ebx
test   %ebx,%ebx
jle    1170 <main+0x30>
add    $0x1,%rbx
nopl   0x0(%rax)
lea    -0x2(%rbx),%eax
movsbl (%r12,%rax,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11b0 <main+0x70>
jmp    1170 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %6
6: ; preds = %34, %0
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %37
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 1, %11
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = call i32 @gets(i8* %16)
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
store i32 %19, i32* %2
br label %20
20: ; preds = %31, %9
%21 = load i32, i32* %2
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %2
%33 = add nsw i32 %32, -1
store i32 %33, i32* %2
br label %20
34: ; preds = %20
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %6
37: ; preds = %6
ret i32 0
}

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