#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*/ is_prime(int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
bool right_trunc(char *s, int len) {
  for (int i = len - 1; i >= 0; i--) {
    int n;
    sscanf(s, "%i", &n);
    if (!is_prime(n)) {
      return false;
    }
    s[i] = '\0';
  }
  return true;
}


x86 assembly (clang, -O0):
<right_trunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     118d <right_trunc+0x6d>
mov    -0x10(%rbp),%rdi
lea    0xeb3(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x1c(%rbp),%edi
call   1030 <is_prime@plt>
cmp    $0x0,%eax
jne    1173 <right_trunc+0x53>
movl   $0x0,-0x4(%rbp)
jmp    1194 <right_trunc+0x74>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1138 <right_trunc+0x18>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<right_trunc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%r14d
test   %esi,%esi
jle    1185 <right_trunc+0x65>
mov    %esi,%ebp
mov    %rdi,%r13
mov    %esi,%ebx
add    $0x1,%rbx
add    $0xffffffff,%ebp
lea    0xeb6(%rip),%r15
lea    0x4(%rsp),%r12
nop
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <sscanf@plt>
mov    0x4(%rsp),%edi
call   1030 <is_prime@plt>
test   %eax,%eax
je     1182 <right_trunc+0x62>
mov    %ebp,%eax
movb   $0x0,0x0(%r13,%rax,1)
add    $0xffffffffffffffff,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%rbx
jg     1150 <right_trunc+0x30>
jmp    1185 <right_trunc+0x65>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
define i32 @right_trunc(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %6
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %6
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i8*, i8** %4
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%16 = load i32, i32* %7
%17 = call i32 @is_prime(i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %13
store i32 0, i32* %3
br label %29
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %20
%26 = load i32, i32* %6
%27 = add nsw i32 %26, -1
store i32 %27, i32* %6
br label %10
28: ; preds = %10
store i32 1, i32* %3
br label %29
29: ; preds = %28, %19
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define i32 @right_trunc(i8* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %22
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %5, %16
%9 = phi i64 [ %7, %5 ], [ %20, %16 ]
%10 = phi i32 [ %1, %5 ], [ %11, %16 ]
%11 = add nsw i32 %10, -1
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
%14 = call i32 @is_prime(i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %8
%17 = zext i32 %11 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 0, i8* %18
%19 = icmp sgt i64 %9, 1
%20 = add nsw i64 %9, -1
br i1 %19, label %8, label %22
21: ; preds = %8
br label %22
22: ; preds = %16, %2, %21
%23 = phi i32 [ 0, %21 ], [ 1, %2 ], [ 1, %16 ]
ret i32 %23
}