#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*/ fgets(char *, int, int /*<<< orphan*/);
unsigned int pow(int, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int /*<<< orphan*/ stdin;
int strlen(char *);
char *strrev(char *);
int main() {
  char s[82];
  unsigned n, nlen, ntmp;
  printf("Enter a string and a number.\n");
  fgets(s, 80, stdin);
  scanf(" %u%*c", &n);
  s[strlen(s) - 1] = '\0';
  nlen = 0, ntmp = n;
  do
    ++nlen;
  while (ntmp /= 10);
  ntmp = 0;
  do
    ntmp += (n % 10) * pow(10, --nlen);
  while (n /= 10);
  n = ntmp;
  printf("Reversed string:\n%s\n\nReversed number: %u\n", strrev(s), n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1050 <fgets@plt>
lea    0xe83(%rip),%rdi
lea    -0x64(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
movl   $0x0,-0x68(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
mov    -0x6c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x6c(%rbp)
cmp    $0x0,%eax
jne    11c4 <main+0x64>
movl   $0x0,-0x6c(%rbp)
mov    -0x64(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x70(%rbp)
mov    -0x68(%rbp),%esi
add    $0xffffffff,%esi
mov    %esi,-0x68(%rbp)
mov    $0xa,%edi
call   1080 <pow@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
imul   %ecx,%eax
add    -0x6c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x64(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jne    11ec <main+0x8c>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    -0x60(%rbp),%rdi
call   1070 <strrev@plt>
mov    %rax,%rsi
mov    -0x64(%rbp),%edx
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1060 <fgets@plt>
lea    0xe58(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    $0xffffffff,%ebp
mov    0xc(%rsp),%ebx
mov    $0xcccccccd,%eax
mov    %ebx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edx
imul   %rax,%rdx
shr    $0x23,%rdx
add    $0x1,%ebp
cmp    $0x9,%ecx
mov    %edx,%ecx
ja     11e0 <main+0x70>
xor    %r14d,%r14d
mov    $0xcccccccd,%r15d
nopl   (%rax)
mov    %ebx,%eax
imul   %r15,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    $0xa,%edi
mov    %ebp,%esi
call   1090 <pow@plt>
imul   %ebx,%eax
add    %eax,%r14d
mov    0xc(%rsp),%eax
mov    %rax,%rbx
imul   %r15,%rbx
shr    $0x23,%rbx
add    $0xffffffff,%ebp
mov    %ebx,0xc(%rsp)
cmp    $0x9,%rax
ja     1200 <main+0x90>
mov    %r14d,0xc(%rsp)
lea    0x10(%rsp),%rdi
call   1080 <strrev@plt>
mov    0xc(%rsp),%edx
lea    0xdae(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Enter a string and a number.\0A\00"
@stdin = global i32 0
@.str.1 = [7 x i8] c" %u%*c\00"
@.str.2 = [42 x i8] c"Reversed string:\0A%s\0A\0AReversed number: %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [82 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [82 x i8], [82 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 80, i32 %8)
%10 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = getelementptr inbounds [82 x i8], [82 x i8]* %2, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [82 x i8], [82 x i8]* %2, i64 0, i64 %14
store i8 0, i8* %15
store i32 0, i32* %4
%16 = load i32, i32* %3
store i32 %16, i32* %5
br label %17
17: ; preds = %20, %0
%18 = load i32, i32* %4
%19 = add i32 %18, 1
store i32 %19, i32* %4
br label %20
20: ; preds = %17
%21 = load i32, i32* %5
%22 = udiv i32 %21, 10
store i32 %22, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %17, label %24
24: ; preds = %20
store i32 0, i32* %5
br label %25
25: ; preds = %34, %24
%26 = load i32, i32* %3
%27 = urem i32 %26, 10
%28 = load i32, i32* %4
%29 = add i32 %28, -1
store i32 %29, i32* %4
%30 = call i32 @pow(i32 10, i32 %29)
%31 = mul i32 %27, %30
%32 = load i32, i32* %5
%33 = add i32 %32, %31
store i32 %33, i32* %5
br label %34
34: ; preds = %25
%35 = load i32, i32* %3
%36 = udiv i32 %35, 10
store i32 %36, i32* %3
%37 = icmp ne i32 %36, 0
br i1 %37, label %25, label %38
38: ; preds = %34
%39 = load i32, i32* %5
store i32 %39, i32* %3
%40 = getelementptr inbounds [82 x i8], [82 x i8]* %2, i64 0, i64 0
%41 = call i8* @strrev(i8* %40)
%42 = load i32, i32* %3
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %41, i32 %42)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [7 x i8] c" %u%*c\00"
@.str.2 = [42 x i8] c"Reversed string:\0A%s\0A\0AReversed number: %u\0A\00"
@str = [29 x i8] c"Enter a string and a number.\00"
define i32 @main() {
%1 = alloca [82 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [82 x i8], [82 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 80, i32 %6)
%8 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = call i32 @strlen(i8* %3)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [82 x i8], [82 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = load i32, i32* %2
br label %14
14: ; preds = %14, %0
%15 = phi i32 [ 0, %0 ], [ %17, %14 ]
%16 = phi i32 [ %13, %0 ], [ %18, %14 ]
%17 = add i32 %15, 1
%18 = udiv i32 %16, 10
%19 = icmp ult i32 %16, 10
br i1 %19, label %20, label %14
20: ; preds = %14, %20
%21 = phi i32 [ %30, %20 ], [ %13, %14 ]
%22 = phi i32 [ %25, %20 ], [ %17, %14 ]
%23 = phi i32 [ %28, %20 ], [ 0, %14 ]
%24 = urem i32 %21, 10
%25 = add i32 %22, -1
%26 = call i32 @pow(i32 10, i32 %25)
%27 = mul i32 %24, %26
%28 = add i32 %27, %23
%29 = load i32, i32* %2
%30 = udiv i32 %29, 10
store i32 %30, i32* %2
%31 = icmp ult i32 %29, 10
br i1 %31, label %32, label %20
32: ; preds = %20
store i32 %28, i32* %2
%33 = call i8* @strrev(i8* %3)
%34 = load i32, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %34)
ret i32 0
}