#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*/ assert(char *);
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int words_reversing() {
  char *output_string = calloc(10000, sizeof(*output_string));
  assert(output_string);
  getchar();
  scanf("%[^\n]s", output_string);
  for (int i = strlen(output_string) - 1; i >= 0; i--) {
    putchar(output_string[i]);
  }
  free(output_string);
  output_string = 0;
  return 0;
}


x86 assembly (clang, -O0):
<words_reversing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x2710,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <assert@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x8(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11e3 <words_reversing+0x73>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11ba <words_reversing+0x4a>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<words_reversing>:
push   %r14
push   %rbx
push   %rax
mov    $0x2710,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <assert@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0xe64(%rip),%rdi
mov    %r14,%rsi
call   1090 <scanf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11d7 <words_reversing+0x67>
mov    %eax,%ebx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
movsbl (%r14,%rax,1),%edi
call   1040 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11c0 <words_reversing+0x50>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%[^\0A]s\00"
define i32 @words_reversing() {
%1 = alloca i8*
%2 = alloca i32
%3 = call i8* @calloc(i32 10000, i32 1)
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = call i32 @assert(i8* %4)
%6 = call i32 (...) @getchar()
%7 = load i8*, i8** %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %1
%10 = call i32 @strlen(i8* %9)
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %2
br label %12
12: ; preds = %22, %0
%13 = load i32, i32* %2
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i8*, i8** %1
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = call i32 @putchar(i8 signext %20)
br label %22
22: ; preds = %15
%23 = load i32, i32* %2
%24 = add nsw i32 %23, -1
store i32 %24, i32* %2
br label %12
25: ; preds = %12
%26 = load i8*, i8** %1
%27 = call i32 @free(i8* %26)
store i8* null, i8** %1
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%[^\0A]s\00"
define i32 @words_reversing() {
%1 = tail call dereferenceable_or_null(10000) i8* @calloc(i32 10000, i32 1)
%2 = tail call i32 @assert(i8* %1)
%3 = tail call i32 (...) @getchar()
%4 = tail call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = zext i32 %5 to i64
br label %11
9: ; preds = %11, %0
%10 = tail call i32 @free(i8* %1)
ret i32 0
11: ; preds = %7, %11
%12 = phi i64 [ %8, %7 ], [ %13, %11 ]
%13 = add nsw i64 %12, -1
%14 = and i64 %13, 4294967295
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = load i8, i8* %15
%17 = tail call i32 @putchar(i8 signext %16)
%18 = icmp ugt i64 %12, 1
br i1 %18, label %11, label %9
}