#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*/ printf(char *, ...);
scalar_t__ ripetizioni(char *, int);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char s[20 + 1];
  int i, s_len;
  int p = 0;
  printf("Stringa? ");
  scanf("%s", s);
  while (strcmp(s, "stop") != 0) {
    p = 0;
    s_len = strlen(s);
    for (i = 1; i < s_len && p == 0; i++) {
      if (s_len % i == 0) {
        if (ripetizioni(s, i) > 0)
          p = i;
      }
    }
    if (p > 0)
      printf("La stringa %s e` periodica (periodo %d).\n", s, p);
    else
      printf("La stringa %s non e` periodica.\n", s);
    printf("Stringa? ");
    scanf("%s", s);
  }
  printf("Programma terminato.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1287 <main+0x137>
movl   $0x0,-0x3c(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x38(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
xor    %eax,%eax
cmp    -0x38(%rbp),%ecx
mov    %al,-0x3d(%rbp)
jge    11da <main+0x8a>
cmpl   $0x0,-0x3c(%rbp)
sete   %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    11ea <main+0x9a>
jmp    122e <main+0xde>
mov    -0x38(%rbp),%eax
cltd
idivl  -0x34(%rbp)
cmp    $0x0,%edx
jne    121b <main+0xcb>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1070 <ripetizioni@plt>
cmp    $0x0,%rax
jle    1216 <main+0xc6>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    121b <main+0xcb>
jmp    1220 <main+0xd0>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11bf <main+0x6f>
cmpl   $0x0,-0x3c(%rbp)
jle    1252 <main+0x102>
lea    -0x30(%rbp),%rsi
mov    -0x3c(%rbp),%edx
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <main+0x114>
lea    -0x30(%rbp),%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xd8d(%rip),%rdi
call   1060 <scanf@plt>
jmp    118b <main+0x3b>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8b(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe84(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     127f <main+0x11f>
mov    %rsp,%rbx
lea    0xe4d(%rip),%r13
lea    0xe50(%rip),%r12
lea    0xe4c(%rip),%rbp
jmp    1206 <main+0xa6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe65(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     127f <main+0x11f>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     11d0 <main+0x70>
mov    %eax,%r14d
mov    $0x2,%r12d
nopl   0x0(%rax)
lea    -0x1(%r12),%ebp
mov    %r14d,%eax
cltd
idiv   %ebp
mov    %edx,%eax
xor    %edx,%edx
test   %eax,%eax
jne    1246 <main+0xe6>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <ripetizioni@plt>
test   %rax,%rax
cmovle %r15d,%ebp
mov    %ebp,%edx
cmp    %r14d,%r12d
jge    1253 <main+0xf3>
add    $0x1,%r12d
test   %edx,%edx
je     1220 <main+0xc0>
test   %edx,%edx
lea    0xdae(%rip),%r12
lea    0xdaa(%rip),%rbp
jle    11d0 <main+0x70>
lea    0xda2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11e1 <main+0x81>
lea    0xdd7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Stringa? \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"stop\00"
@.str.3 = [42 x i8] c"La stringa %s e` periodica (periodo %d).\0A\00"
@.str.4 = [33 x i8] c"La stringa %s non e` periodica.\0A\00"
@.str.5 = [22 x i8] c"Programma terminato.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [21 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %56, %2
%14 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %60
17: ; preds = %13
store i32 0, i32* %9
%18 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %8
store i32 1, i32* %7
br label %20
20: ; preds = %43, %17
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 0
br label %27
27: ; preds = %24, %20
%28 = phi i1 [ false, %20 ], [ %26, %24 ]
br i1 %28, label %29, label %46
29: ; preds = %27
%30 = load i32, i32* %8
%31 = load i32, i32* %7
%32 = srem i32 %30, %31
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %29
%35 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%36 = load i32, i32* %7
%37 = call i64 @ripetizioni(i8* %35, i32 %36)
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = load i32, i32* %7
store i32 %40, i32* %9
br label %41
41: ; preds = %39, %34
br label %42
42: ; preds = %41, %29
br label %43
43: ; preds = %42
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %20
46: ; preds = %27
%47 = load i32, i32* %9
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%51 = load i32, i32* %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %50, i32 %51)
br label %56
53: ; preds = %46
%54 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %53, %49
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%58 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%59 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %58)
br label %13
60: ; preds = %13
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"Stringa? \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"stop\00"
@.str.3 = [42 x i8] c"La stringa %s e` periodica (periodo %d).\0A\00"
@.str.4 = [33 x i8] c"La stringa %s non e` periodica.\0A\00"
@str = [21 x i8] c"Programma terminato.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [21 x i8]
%4 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %37, label %9
9: ; preds = %2, %32
%10 = call i32 @strlen(i8* %4)
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %30
12: ; preds = %9, %20
%13 = phi i32 [ %22, %20 ], [ 1, %9 ]
%14 = srem i32 %10, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = call i64 @ripetizioni(i8* %4, i32 %13)
%18 = icmp sgt i64 %17, 0
%19 = select i1 %18, i32 %13, i32 0
br label %20
20: ; preds = %16, %12
%21 = phi i32 [ 0, %12 ], [ %19, %16 ]
%22 = add nuw nsw i32 %13, 1
%23 = icmp slt i32 %22, %10
%24 = icmp eq i32 %21, 0
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %12, label %26
26: ; preds = %20
%27 = icmp sgt i32 %21, 0
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %21)
br label %32
30: ; preds = %9, %26
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %32
32: ; preds = %30, %28
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%35 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %9
37: ; preds = %32, %2
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
ret i32 0
}