#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 atoi(char *);
int /*<<< orphan*/ is_prime(int);
int strlen(char *);
int prime_forwards(char *prime) {
  int length = strlen(prime);
  char forwards[length + 1];
  for (int i = 0; i < length; i++) {
    forwards[i] = prime[i];
    forwards[i + 1] = '\0';
    int prime_slice = atoi(forwards);
    if (!is_prime(prime_slice))
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<prime_forwards>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e5 <prime_forwards+0xb5>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x2c(%rbp),%rax
mov    %cl,(%rdi,%rax,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,(%rdi,%rax,1)
call   1050 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   1040 <is_prime@plt>
cmp    $0x0,%eax
jne    11d2 <prime_forwards+0xa2>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11f3 <prime_forwards+0xc3>
jmp    11d7 <prime_forwards+0xa7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1178 <prime_forwards+0x48>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prime_forwards>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    0x1(%rax),%ecx
mov    %rsp,%r13
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
xor    %r14d,%r14d
test   %eax,%eax
mov    $0x0,%r12d
mov    %rax,-0x30(%rbp)
cmovg  %eax,%r12d
nopl   (%rax)
mov    %r14,%rbx
cmp    %r14,%r12
je     119f <prime_forwards+0x6f>
movzbl (%r15,%rbx,1),%eax
mov    %al,0x0(%r13,%rbx,1)
lea    0x1(%rbx),%r14
movb   $0x0,0x1(%r13,%rbx,1)
mov    %r13,%rdi
call   1050 <atoi@plt>
mov    %eax,%edi
call   1040 <is_prime@plt>
test   %eax,%eax
jne    1170 <prime_forwards+0x40>
movslq -0x30(%rbp),%rcx
xor    %eax,%eax
cmp    %rcx,%rbx
setge  %al
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @prime_forwards(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %5
%16 = alloca i8, i64 %14
store i64 %14, i64* %6
store i32 0, i32* %7
br label %17
17: ; preds = %40, %1
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %16, i64 %28
store i8 %26, i8* %29
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %16, i64 %32
store i8 0, i8* %33
%34 = call i32 @atoi(i8* %16)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = call i32 @is_prime(i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %21
store i32 0, i32* %2
store i32 1, i32* %9
br label %44
39: ; preds = %21
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %17
43: ; preds = %17
store i32 1, i32* %2
store i32 1, i32* %9
br label %44
44: ; preds = %43, %38
%45 = load i8*, i8** %5
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
define i32 @prime_forwards(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @llvm.smax.i32(i32 %2, i32 0)
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %11, %1
%9 = phi i64 [ %15, %11 ], [ 0, %1 ]
%10 = icmp eq i64 %9, %7
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %0, i64 %9
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 %13, i8* %14
%15 = add nuw nsw i64 %9, 1
%16 = getelementptr inbounds i8, i8* %5, i64 %15
store i8 0, i8* %16
%17 = call i32 @atoi(i8* %5)
%18 = tail call i32 @is_prime(i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %8
20: ; preds = %8, %11
%21 = sext i32 %2 to i64
%22 = icmp sge i64 %9, %21
%23 = zext i1 %22 to i32
ret i32 %23
}