#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 */
char EOF;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ Reverse(char *, int, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char getchar();
scalar_t__ isdigit(char);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(void) {
  int capacity = 4;
  char *buffer = (char *)calloc(capacity, sizeof(char));
  if (!buffer) {
    return EXIT_FAILURE;
  }
  int count = 0;
  char c = '\0';
  int isValid = 0;
  while (!isValid) {
    printf("Please enter an integer you want reversed: ");
    isValid = 1;
    while ((c = getchar()) != '\n' && c != EOF) {
      if (count + 1 >= capacity) {
        int newCapacity = (capacity > 0) ? capacity * 2 : 4;
        char *newBuffer = (char *)calloc(newCapacity, sizeof(char));
        if (!newBuffer) {
          return EXIT_FAILURE;
        }
        memcpy(newBuffer, buffer, sizeof(char) * count);
        free(buffer);
        buffer = newBuffer;
        capacity = newCapacity;
      }
      if (isdigit(c)) {
        buffer[count] = c;
        ++count;
      } else {
        isValid = 0;
      }
    }
    if (count == 0)
      isValid = 0;
    buffer[count] = '\0';
    if (!isValid) {
      fprintf(stderr, "Input invalid. Please try again.\n");
      count = 0;
    }
  }
  Reverse((char *)buffer, sizeof(char), count);
  printf("Reversed: %s\n", buffer);
  free(buffer);
  getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <main+0x43>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1398 <main+0x218>
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11eb <main+0x6b>
jmp    1359 <main+0x1d9>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x29(%rbp)
je     1231 <main+0xb1>
movsbl -0x15(%rbp),%eax
mov    0x2dc2(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1241 <main+0xc1>
jmp    1311 <main+0x191>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jl     12d6 <main+0x156>
cmpl   $0x0,-0x8(%rbp)
jle    1268 <main+0xe8>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1275 <main+0xf5>
mov    $0x4,%eax
mov    %eax,-0x30(%rbp)
jmp    1275 <main+0xf5>
mov    -0x30(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12a8 <main+0x128>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1398 <main+0x218>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1090 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x8(%rbp)
movsbl -0x15(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1305 <main+0x185>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    130c <main+0x18c>
movl   $0x0,-0x1c(%rbp)
jmp    1200 <main+0x80>
cmpl   $0x0,-0x14(%rbp)
jne    1322 <main+0x1a2>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x1c(%rbp)
jne    1354 <main+0x1d4>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
lea    0xce4(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
jmp    11d5 <main+0x55>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   10a0 <Reverse@plt>
mov    -0x10(%rbp),%rsi
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    0x2c35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x4,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    0x2e2c(%rip),%rcx
mov    %rax,(%rsp)
test   %rax,%rax
je     12ec <main+0x16c>
lea    0xe48(%rip),%r14
mov    0x2e29(%rip),%r15
mov    $0x4,%ebp
jmp    11ec <main+0x6c>
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%rax
movb   $0x0,(%rax)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1080 <fprintf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     11d0 <main+0x50>
mov    %eax,%ebx
cmp    (%r15),%al
je     11d0 <main+0x50>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
movl   $0x1,0x14(%rsp)
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
lea    0x1(%rax),%r14d
cmp    %ebp,%r14d
jl     1276 <main+0xf6>
test   %ebp,%ebp
lea    0x0(%rbp,%rbp,1),%eax
mov    %eax,%ebp
mov    $0x4,%eax
cmovle %eax,%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     12e5 <main+0x165>
mov    %rax,%r12
mov    %rax,%rdi
mov    (%rsp),%r13
mov    %r13,%rsi
mov    0x8(%rsp),%rdx
call   1090 <memcpy@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,(%rsp)
movsbl %bl,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     12a0 <main+0x120>
movslq 0x8(%rsp),%rax
mov    (%rsp),%rcx
mov    %bl,(%rcx,%rax,1)
mov    %r14d,%eax
mov    %rax,0x8(%rsp)
jmp    12a8 <main+0x128>
nopl   0x0(%rax)
movl   $0x0,0x14(%rsp)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     12be <main+0x13e>
mov    %eax,%ebx
cmp    (%r15),%al
jne    1220 <main+0xa0>
mov    0x8(%rsp),%rdx
movslq %edx,%rax
mov    (%rsp),%rcx
movb   $0x0,(%rcx,%rax,1)
test   %edx,%edx
je     12d9 <main+0x159>
cmpl   $0x0,0x14(%rsp)
jne    12fd <main+0x17d>
lea    0xd20(%rip),%r14
jmp    11d7 <main+0x57>
mov    0x2ce4(%rip),%rcx
mov    (%rcx),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    0x8(%rsp),%rdx
call   10a0 <Reverse@plt>
lea    0xd34(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2c8e(%rip),%rcx
jmp    12ec <main+0x16c>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [44 x i8] c"Please enter an integer you want reversed: \00"
@EOF = global i8 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Input invalid. Please try again.\0A\00"
@.str.2 = [14 x i8] c"Reversed: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %1
store i32 4, i32* %2
%9 = load i32, i32* %2
%10 = call i64 @calloc(i32 %9, i32 1)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %0
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %1
br label %107
16: ; preds = %0
store i32 0, i32* %4
store i8 0, i8* %5
store i32 0, i32* %6
br label %17
17: ; preds = %96, %16
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %97
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %23
23: ; preds = %81, %21
%24 = call signext i8 (...) @getchar()
store i8 %24, i8* %5
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 10
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i8, i8* %5
%29 = sext i8 %28 to i32
%30 = load i8, i8* @EOF
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %29, %31
br label %33
33: ; preds = %27, %23
%34 = phi i1 [ false, %23 ], [ %32, %27 ]
br i1 %34, label %35, label %82
35: ; preds = %33
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %2
%39 = icmp sge i32 %37, %38
br i1 %39, label %40, label %68
40: ; preds = %35
%41 = load i32, i32* %2
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* %2
%45 = mul nsw i32 %44, 2
br label %47
46: ; preds = %40
br label %47
47: ; preds = %46, %43
%48 = phi i32 [ %45, %43 ], [ 4, %46 ]
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = call i64 @calloc(i32 %49, i32 1)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %8
%52 = load i8*, i8** %8
%53 = icmp ne i8* %52, null
br i1 %53, label %56, label %54
54: ; preds = %47
%55 = load i32, i32* @EXIT_FAILURE
store i32 %55, i32* %1
br label %107
56: ; preds = %47
%57 = load i8*, i8** %8
%58 = load i8*, i8** %3
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = mul i64 1, %60
%62 = trunc i64 %61 to i32
%63 = call i32 @memcpy(i8* %57, i8* %58, i32 %62)
%64 = load i8*, i8** %3
%65 = call i32 @free(i8* %64)
%66 = load i8*, i8** %8
store i8* %66, i8** %3
%67 = load i32, i32* %7
store i32 %67, i32* %2
br label %68
68: ; preds = %56, %35
%69 = load i8, i8* %5
%70 = call i64 @isdigit(i8 signext %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %80
72: ; preds = %68
%73 = load i8, i8* %5
%74 = load i8*, i8** %3
%75 = load i32, i32* %4
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
store i8 %73, i8* %77
%78 = load i32, i32* %4
%79 = add nsw i32 %78, 1
store i32 %79, i32* %4
br label %81
80: ; preds = %68
store i32 0, i32* %6
br label %81
81: ; preds = %80, %72
br label %23
82: ; preds = %33
%83 = load i32, i32* %4
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %86
85: ; preds = %82
store i32 0, i32* %6
br label %86
86: ; preds = %85, %82
%87 = load i8*, i8** %3
%88 = load i32, i32* %4
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
store i8 0, i8* %90
%91 = load i32, i32* %6
%92 = icmp ne i32 %91, 0
br i1 %92, label %96, label %93
93: ; preds = %86
%94 = load i32, i32* @stderr
%95 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %96
96: ; preds = %93, %86
br label %17
97: ; preds = %17
%98 = load i8*, i8** %3
%99 = load i32, i32* %4
%100 = call i32 @Reverse(i8* %98, i32 1, i32 %99)
%101 = load i8*, i8** %3
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %101)
%103 = load i8*, i8** %3
%104 = call i32 @free(i8* %103)
%105 = call signext i8 (...) @getchar()
%106 = load i32, i32* @EXIT_SUCCESS
store i32 %106, i32* %1
br label %107
107: ; preds = %97, %54, %14
%108 = load i32, i32* %1
ret i32 %108
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [44 x i8] c"Please enter an integer you want reversed: \00"
@EOF = global i8 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Input invalid. Please try again.\0A\00"
@.str.2 = [14 x i8] c"Reversed: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i64 @calloc(i32 4, i32 1)
%2 = icmp eq i64 %1, 0
br i1 %2, label %65, label %3
3: ; preds = %0
%4 = inttoptr i64 %1 to i8*
br label %5
5: ; preds = %55, %3
%6 = phi i32 [ 4, %3 ], [ %56, %55 ]
%7 = phi i8* [ %4, %3 ], [ %57, %55 ]
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%9 = tail call signext i8 (...) @getchar()
%10 = icmp ne i8 %9, 10
%11 = load i8, i8* @EOF
%12 = icmp ne i8 %9, %11
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %15, label %14
14: ; preds = %5
store i8 0, i8* %7
br label %55
15: ; preds = %5, %41
%16 = phi i8 [ %44, %41 ], [ %9, %5 ]
%17 = phi i32 [ %35, %41 ], [ %6, %5 ]
%18 = phi i32 [ %43, %41 ], [ 1, %5 ]
%19 = phi i32 [ %42, %41 ], [ 0, %5 ]
%20 = phi i8* [ %34, %41 ], [ %7, %5 ]
%21 = add nsw i32 %19, 1
%22 = icmp slt i32 %21, %17
br i1 %22, label %33, label %23
23: ; preds = %15
%24 = icmp sgt i32 %17, 0
%25 = shl nsw i32 %17, 1
%26 = select i1 %24, i32 %25, i32 4
%27 = tail call i64 @calloc(i32 %26, i32 1)
%28 = inttoptr i64 %27 to i8*
%29 = icmp eq i64 %27, 0
br i1 %29, label %65, label %30
30: ; preds = %23
%31 = tail call i32 @memcpy(i8* %28, i8* %20, i32 %19)
%32 = tail call i32 @free(i8* %20)
br label %33
33: ; preds = %30, %15
%34 = phi i8* [ %28, %30 ], [ %20, %15 ]
%35 = phi i32 [ %26, %30 ], [ %17, %15 ]
%36 = tail call i64 @isdigit(i8 signext %16)
%37 = icmp eq i64 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = sext i32 %19 to i64
%40 = getelementptr inbounds i8, i8* %34, i64 %39
store i8 %16, i8* %40
br label %41
41: ; preds = %33, %38
%42 = phi i32 [ %21, %38 ], [ %19, %33 ]
%43 = phi i32 [ %18, %38 ], [ 0, %33 ]
%44 = tail call signext i8 (...) @getchar()
%45 = icmp ne i8 %44, 10
%46 = load i8, i8* @EOF
%47 = icmp ne i8 %44, %46
%48 = select i1 %45, i1 %47, i1 false
br i1 %48, label %15, label %49
49: ; preds = %41
%50 = icmp eq i32 %42, 0
%51 = sext i32 %42 to i64
%52 = getelementptr inbounds i8, i8* %34, i64 %51
store i8 0, i8* %52
%53 = icmp eq i32 %43, 0
%54 = select i1 %50, i1 true, i1 %53
br i1 %54, label %55, label %60
55: ; preds = %14, %49
%56 = phi i32 [ %6, %14 ], [ %35, %49 ]
%57 = phi i8* [ %7, %14 ], [ %34, %49 ]
%58 = load i32, i32* @stderr
%59 = tail call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %5
60: ; preds = %49
%61 = tail call i32 @Reverse(i8* %34, i32 1, i32 %42)
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%63 = tail call i32 @free(i8* %34)
%64 = tail call signext i8 (...) @getchar()
br label %65
65: ; preds = %23, %0, %60
%66 = phi i32* [ @EXIT_SUCCESS, %60 ], [ @EXIT_FAILURE, %0 ], [ @EXIT_FAILURE, %23 ]
%67 = load i32, i32* %66
ret i32 %67
}