#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 */
typedef int /*<<< orphan*/ b;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main(int argc, char const *argv[]) {
  int a, i;
  do {
    scanf("%d", &a);
    char *b = (char *)malloc(a * sizeof(char));
    fgets(b, sizeof(b), stdin);
    for (i = a; i >= 0; --i) {
      printf("%c", b[i]);
    }
    free(b);
    b = NULL;
  } while (a != 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1050 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11d6 <main+0x86>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xe44(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11a6 <main+0x56>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1166 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%r14
lea    0x4(%rsp),%r15
mov    0x2e7a(%rip),%r13
lea    0xe8e(%rip),%r12
jmp    118f <main+0x3f>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <free@plt>
cmpl   $0x0,0x4(%rsp)
je     11d4 <main+0x84>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x0(%r13),%edx
mov    %rax,%rdi
mov    $0x8,%esi
call   1050 <fgets@plt>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
js     1180 <main+0x30>
nop
movsbl (%rbx,%rbp,1),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbp
jb     11c0 <main+0x70>
jmp    1180 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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