#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
char *destination;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *make_char(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int remove_new_line(char *);
int /*<<< orphan*/ reverse_string(char *, char *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ stdin;
int main() {
  char source[50];
  char *destination = make_char(destination, 50);
  if (destination == NULL) {
    printf("Not enough memory!");
    exit(EXIT_FAILURE);
  }
  printf("Enter a string to reverse: ");
  fgets(source, 50, stdin);
  int lenght = remove_new_line(source);
  reverse_string(source, destination, lenght, 0, lenght - 2);
  printf("Reversed: %s", destination);
  free(destination);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x48(%rbp),%rax
mov    %eax,%edi
mov    $0x32,%esi
call   1090 <make_char@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11ba <main+0x4a>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
mov    $0x32,%esi
call   1060 <fgets@plt>
lea    -0x40(%rbp),%rdi
call   1070 <remove_new_line@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x4c(%rbp),%edx
mov    -0x4c(%rbp),%r8d
sub    $0x2,%r8d
xor    %ecx,%ecx
call   1040 <reverse_string@plt>
mov    -0x48(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    $0x32,%esi
call   1090 <make_char@plt>
test   %rax,%rax
je     11f5 <main+0x85>
mov    %rax,%rbx
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x32,%esi
call   1060 <fgets@plt>
mov    %r14,%rdi
call   1070 <remove_new_line@plt>
lea    -0x2(%rax),%r8d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <reverse_string@plt>
lea    0xe5d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Not enough memory!\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"Enter a string to reverse: \00"
@stdin = global i32 0
@.str.2 = [13 x i8] c"Reversed: %s\00"
@EXIT_SUCCESS = global i32 0
@destination = global i8* null
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = load i8*, i8** %3
%6 = ptrtoint i8* %5 to i32
%7 = call i8* @make_char(i32 %6, i32 50)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %16, i32 50, i32 %17)
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%20 = call i32 @remove_new_line(i8* %19)
store i32 %20, i32* %4
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 2
%26 = call i32 @reverse_string(i8* %21, i8* %22, i32 %23, i32 0, i32 %25)
%27 = load i8*, i8** %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %3
%30 = call i32 @free(i8* %29)
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}

LLVM IR (-O2):
@.str = [19 x i8] c"Not enough memory!\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"Enter a string to reverse: \00"
@stdin = global i32 0
@.str.2 = [13 x i8] c"Reversed: %s\00"
@EXIT_SUCCESS = global i32 0
@destination = global i8* null
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @make_char(i32 undef, i32 50)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %2, i32 50, i32 %11)
%13 = call i32 @remove_new_line(i8* %2)
%14 = add nsw i32 %13, -2
%15 = call i32 @reverse_string(i8* %2, i8* %3, i32 %13, i32 0, i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%17 = call i32 @free(i8* %3)
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}