#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 EXIT_SUCCESS;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ isdigit(char);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ stdin;
int main(void) {
  char *str = malloc(100);
  char *fr = str;
  char *last = "0";
  fgets(str, 100, stdin);
  while (*str++) {
    if (isdigit(*str))
      last = str;
  };
  printf("%c is the last digit\n", *last);
  free(fr);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe84(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,(%rax)
je     11d2 <main+0x82>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     11cd <main+0x7d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1197 <main+0x47>
mov    -0x20(%rbp),%rax
lea    0xe25(%rip),%rdi
movsbl (%rax),%esi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
cmpb   $0x0,(%r14)
je     11aa <main+0x5a>
mov    %r14,%rbx
add    $0x1,%rbx
lea    0xe74(%rip),%r15
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
cmovne %rbx,%r15
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1190 <main+0x40>
jmp    11b1 <main+0x61>
lea    0xe4f(%rip),%r15
movsbl (%r15),%esi
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@stdin = global i32 0
@.str.1 = [22 x i8] c"%c is the last digit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i8* @malloc(i32 100)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4
%7 = load i8*, i8** %2
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 100, i32 %8)
br label %10
10: ; preds = %22, %0
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %2
%13 = load i8, i8* %11
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i8*, i8** %2
store i8* %21, i8** %4
br label %22
22: ; preds = %20, %15
br label %10
23: ; preds = %10
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8 signext %25)
%27 = load i8*, i8** %3
%28 = call i32 @free(i8* %27)
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@stdin = global i32 0
@.str.1 = [22 x i8] c"%c is the last digit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%2 = load i32, i32* @stdin
%3 = tail call i32 @fgets(i8* %1, i32 100, i32 %2)
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %0, %6
%7 = phi i8* [ %9, %6 ], [ %1, %0 ]
%8 = phi i8* [ %13, %6 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %0 ]
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = load i8, i8* %9
%11 = tail call i64 @isdigit(i8 signext %10)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8* %8, i8* %9
%14 = load i8, i8* %9
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %6
16: ; preds = %6, %0
%17 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %0 ], [ %13, %6 ]
%18 = load i8, i8* %17
%19 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8 signext %18)
%20 = tail call i32 @free(i8* %1)
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}