#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char str[256 + 1];
  char tmp;
  int passi = 0;
  int scambi;
  int i;
  printf("Inserire una stringa: ");
  gets(str);
  do {
    scambi = 0;
    for (i = 0; str[i + 1] != '\0'; i++) {
      if (str[i] > str[i + 1]) {
        tmp = str[i];
        str[i] = str[i + 1];
        str[i + 1] = tmp;
        scambi = 1;
        printf("  %d: %s\n", passi, str);
      }
    }
    printf("%d: %s\n", passi, str);
    passi++;
  } while (scambi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x118(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <gets@plt>
movl   $0x0,-0x11c(%rbp)
movl   $0x0,-0x120(%rbp)
mov    -0x120(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     123b <main+0x11b>
movslq -0x120(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
mov    -0x120(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl -0x110(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jle    1222 <main+0x102>
movslq -0x120(%rbp),%rax
mov    -0x110(%rbp,%rax,1),%al
mov    %al,-0x111(%rbp)
mov    -0x120(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x110(%rbp,%rax,1),%cl
movslq -0x120(%rbp),%rax
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x111(%rbp),%cl
mov    -0x120(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x110(%rbp,%rax,1)
movl   $0x1,-0x11c(%rbp)
mov    -0x118(%rbp),%esi
lea    -0x110(%rbp),%rdx
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1227 <main+0x107>
mov    -0x120(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x120(%rbp)
jmp    116a <main+0x4a>
mov    -0x118(%rbp),%esi
lea    -0x110(%rbp),%rdx
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
cmpl   $0x0,-0x11c(%rbp)
jne    1156 <main+0x36>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <gets@plt>
lea    0xec6(%rip),%r15
lea    0xec1(%rip),%r12
xor    %r13d,%r13d
jmp    1178 <main+0x58>
nopl   (%rax)
mov    %r12,%rdi
mov    %r13d,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%r13d
test   %ebp,%ebp
je     11d3 <main+0xb3>
mov    0x1(%rsp),%al
test   %al,%al
je     11bf <main+0x9f>
xor    %ebp,%ebp
mov    %r14,%rbx
jmp    119c <main+0x7c>
nopw   0x0(%rax,%rax,1)
movzbl 0x2(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1160 <main+0x40>
movzbl (%rbx),%ecx
cmp    %al,%cl
jle    1190 <main+0x70>
mov    %al,(%rbx)
mov    %cl,0x1(%rbx)
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebp
jmp    1190 <main+0x70>
lea    0xe53(%rip),%rdi
mov    %rsp,%rdx
mov    %r13d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Inserire una stringa: \00"
@.str.1 = [10 x i8] c" %d: %s\0A\00"
@.str.2 = [8 x i8] c"%d: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [257 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 0
%9 = call i32 @gets(i8* %8)
br label %10
10: ; preds = %63, %0
store i32 0, i32* %5
store i32 0, i32* %6
br label %11
11: ; preds = %54, %10
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %57
19: ; preds = %11
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp sgt i32 %24, %30
br i1 %31, label %32, label %53
32: ; preds = %19
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
store i8 %36, i8* %3
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %43
store i8 %41, i8* %44
%45 = load i8, i8* %3
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 %48
store i8 %45, i8* %49
store i32 1, i32* %5
%50 = load i32, i32* %4
%51 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %50, i8* %51)
br label %53
53: ; preds = %32, %19
br label %54
54: ; preds = %53
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %11
57: ; preds = %11
%58 = load i32, i32* %4
%59 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 0
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %58, i8* %59)
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %63
63: ; preds = %57
%64 = load i32, i32* %5
%65 = icmp ne i32 %64, 0
br i1 %65, label %10, label %66
66: ; preds = %63
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Inserire una stringa: \00"
@.str.1 = [10 x i8] c" %d: %s\0A\00"
@.str.2 = [8 x i8] c"%d: %s\0A\00"
define i32 @main() {
%1 = alloca [257 x i8]
%2 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 1
br label %6
6: ; preds = %30, %0
%7 = phi i32 [ 0, %0 ], [ %32, %30 ]
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %2)
br label %34
12: ; preds = %6, %23
%13 = phi i64 [ %29, %23 ], [ 0, %6 ]
%14 = phi i64 [ %25, %23 ], [ 1, %6 ]
%15 = phi i8 [ %27, %23 ], [ %8, %6 ]
%16 = phi i8* [ %26, %23 ], [ %5, %6 ]
%17 = phi i32 [ %24, %23 ], [ 0, %6 ]
%18 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 %13
%19 = load i8, i8* %18
%20 = icmp sgt i8 %19, %15
br i1 %20, label %21, label %23
21: ; preds = %12
store i8 %15, i8* %18
store i8 %19, i8* %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %7, i8* %2)
br label %23
23: ; preds = %12, %21
%24 = phi i32 [ 1, %21 ], [ %17, %12 ]
%25 = add nuw i64 %14, 1
%26 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
%29 = add nuw nsw i64 %13, 1
br i1 %28, label %30, label %12
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %2)
%32 = add nuw nsw i32 %7, 1
%33 = icmp eq i32 %24, 0
br i1 %33, label %34, label %6
34: ; preds = %30, %10
ret i32 0
}