#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 /*<<< orphan*/ puts(char *);
int rand();
void fig05_11() {
  unsigned int i;
  for (i = 1; i <= 20; ++i) {
    printf("%10d", 1 + (rand() % 6));
    if (i % 5 == 0) {
      puts("");
    }
  }
}


x86 assembly (clang, -O0):
<fig05_11>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x4(%rbp)
cmpl   $0x14,-0x4(%rbp)
ja     119d <fig05_11+0x6d>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
add    $0x1,%esi
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x5,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    118a <fig05_11+0x5a>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
jmp    118f <fig05_11+0x5f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    113f <fig05_11+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig05_11>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%bl
lea    0xec0(%rip),%r14
xor    %ebp,%ebp
jmp    115b <fig05_11+0x2b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ebp
add    $0x1,%bl
cmp    $0xffffffec,%ebp
je     11b3 <fig05_11+0x83>
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   1050 <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
call   1040 <printf@plt>
cmp    %bpl,%r15b
jne    1150 <fig05_11+0x20>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <fig05_11+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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