#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 *, int, int);
int rand();
int lancio(int tiri, int dado) {
  int i = 0;
  int tiro = 0;
  int somma = 0;
  for (i = 0; i < tiri; i++) {
    tiro = ((rand() % dado) + 1);
    printf("Tiro %i: %i\n", i + 1, tiro);
    somma = somma + tiro;
  }
  return somma;
}


x86 assembly (clang, -O0):
<lancio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1193 <lancio+0x73>
mov    $0x0,%al
call   1040 <rand@plt>
cltd
idivl  -0x8(%rbp)
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <lancio+0x2a>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lancio>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1187 <lancio+0x67>
mov    %esi,%r14d
mov    %edi,%r12d
neg    %r12d
mov    $0x1,%ebx
lea    0xebc(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %r14d
mov    %edx,%r13d
lea    0x1(%r13),%edx
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    %r13d,%ebp
add    $0x1,%ebp
lea    (%r12,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1150 <lancio+0x30>
jmp    1189 <lancio+0x69>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"Tiro %i: %i\0A\00"
define i32 @lancio(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %14
4: ; preds = %2, %4
%5 = phi i32 [ %12, %4 ], [ 0, %2 ]
%6 = phi i32 [ %10, %4 ], [ 0, %2 ]
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, %1
%9 = add nsw i32 %8, 1
%10 = add nuw nsw i32 %6, 1
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %9)
%12 = add nsw i32 %9, %5
%13 = icmp eq i32 %10, %0
br i1 %13, label %14, label %4
14: ; preds = %4, %2
%15 = phi i32 [ 0, %2 ], [ %12, %4 ]
ret i32 %15
}