#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 /*<<< orphan*/ puts(char *);
int rand();
int /*<<< orphan*/ scanf(char *, unsigned int *);
int /*<<< orphan*/ srand(unsigned int);
void fig05_13() {
  unsigned int i;
  unsigned int seed;
  printf("%s", "Enter seed: \n");
  scanf("%u", &seed);
  srand(seed);
  for (i = 1; i <= 10; ++i) {
    printf("%10d", 1 + (rand() % 6));
    if (i % 5 == 0) {
      puts("");
    }
  }
}


x86 assembly (clang, -O0):
<fig05_13>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1050 <srand@plt>
movl   $0x1,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
ja     11ec <fig05_13+0x9c>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
add    $0x1,%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x5,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    11d9 <fig05_13+0x89>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
jmp    11de <fig05_13+0x8e>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    118c <fig05_13+0x3c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig05_13>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe9a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe86(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
call   1060 <srand@plt>
mov    $0x1,%bl
lea    0xe6d(%rip),%r14
xor    %ebp,%ebp
jmp    11ab <fig05_13+0x4b>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
add    $0x1,%bl
cmp    $0xfffffff6,%ebp
je     1205 <fig05_13+0xa5>
movzbl %bl,%eax
imul   $0xcd,%eax,%eax
shr    $0xa,%eax
lea    (%rax,%rax,4),%eax
mov    $0x1,%r15b
sub    %al,%r15b
xor    %eax,%eax
call   1080 <rand@plt>
cltq
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %bpl,%r15b
jne    11a0 <fig05_13+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11a0 <fig05_13+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [14 x i8] c"Enter seed: \0A\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [5 x i8] c"%10d\00"
@.str.4 = [1 x i8] zeroinitializer
define void @fig05_13() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%5 = load i32, i32* %2
%6 = call i32 @srand(i32 %5)
store i32 1, i32* %1
br label %7
7: ; preds = %21, %0
%8 = load i32, i32* %1
%9 = icmp ule i32 %8, 10
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 6
%13 = add nsw i32 1, %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %1
%16 = urem i32 %15, 5
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %10
br label %21
21: ; preds = %20
%22 = load i32, i32* %1
%23 = add i32 %22, 1
store i32 %23, i32* %1
br label %7
24: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [5 x i8] c"%10d\00"
@str = [13 x i8] c"Enter seed: \00"
define void @fig05_13() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 @srand(i32 %5)
br label %7
7: ; preds = %0, %18
%8 = phi i32 [ 1, %0 ], [ %19, %18 ]
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 6
%11 = add nsw i32 %10, 1
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = trunc i32 %8 to i8
%14 = urem i8 %13, 5
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %7
%17 = call i32 @putchar(i32 10)
br label %18
18: ; preds = %7, %16
%19 = add nuw nsw i32 %8, 1
%20 = icmp eq i32 %19, 11
br i1 %20, label %21, label %7
21: ; preds = %18
ret void
}