int teste_sorteador() {
  set_random(0.5);
  printf("rand() = %f\n", rand());
  printf("sortear(%d) = %d\n", 10, sortear(10));
  do {
    if (!(sortear(10) == 5)) {
      printf("\nfailure in %s() line %d\n", __func__, 13);
      return 1;
    }
  } while (0);
  set_random(0.54);
  printf("sortear(%d) = %d\n", 10, sortear(10));
  do {
    if (!(sortear(10) == 5)) {
      printf("\nfailure in %s() line %d\n", __func__, 17);
      return 1;
    }
  } while (0);
  set_random(0.56);
  printf("sortear(%d) = %d\n", 10, sortear(10));
  do {
    if (!(sortear(10) == 6)) {
      printf("\nfailure in %s() line %d\n", __func__, 21);
      return 1;
    }
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<teste_sorteador>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  0xeb0(%rip),%xmm0
mov    $0x1,%al
call   1030 <set_random@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,%esi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
mov    $0x0,%al
call   1050 <sortear@plt>
mov    %eax,%edx
lea    0xea2(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
mov    $0x0,%al
call   1050 <sortear@plt>
cmp    $0x5,%eax
je     11ca <teste_sorteador+0x8a>
lea    0xe8c(%rip),%rdi
lea    0xe9f(%rip),%rsi
mov    $0xd,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <teste_sorteador+0x176>
jmp    11cf <teste_sorteador+0x8f>
movsd  0xe31(%rip),%xmm0
mov    $0x1,%al
call   1030 <set_random@plt>
mov    $0xa,%edi
mov    $0x0,%al
call   1050 <sortear@plt>
mov    %eax,%edx
lea    0xe32(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
mov    $0x0,%al
call   1050 <sortear@plt>
cmp    $0x5,%eax
je     123a <teste_sorteador+0xfa>
lea    0xe1c(%rip),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x11,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <teste_sorteador+0x176>
jmp    123f <teste_sorteador+0xff>
movsd  0xdc9(%rip),%xmm0
mov    $0x1,%al
call   1030 <set_random@plt>
mov    $0xa,%edi
mov    $0x0,%al
call   1050 <sortear@plt>
mov    %eax,%edx
lea    0xdc2(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
mov    $0x0,%al
call   1050 <sortear@plt>
cmp    $0x6,%eax
je     12aa <teste_sorteador+0x16a>
lea    0xdac(%rip),%rdi
lea    0xdbf(%rip),%rsi
mov    $0x15,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <teste_sorteador+0x176>
jmp    12af <teste_sorteador+0x16f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<teste_sorteador>:
push   %rbx
movsd  0xeb7(%rip),%xmm0
mov    $0x1,%al
call   1030 <set_random@plt>
xor    %eax,%eax
call   1060 <rand@plt>
lea    0xeba(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
xor    %eax,%eax
call   1050 <sortear@plt>
lea    0xeab(%rip),%rdi
mov    $0xa,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
xor    %eax,%eax
call   1050 <sortear@plt>
mov    $0xd,%edx
cmp    $0x5,%eax
jne    1230 <teste_sorteador+0xf0>
movsd  0xe5e(%rip),%xmm0
mov    $0x1,%al
call   1030 <set_random@plt>
xor    %ebx,%ebx
mov    $0xa,%edi
xor    %eax,%eax
call   1050 <sortear@plt>
lea    0xe5f(%rip),%rdi
mov    $0xa,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
xor    %eax,%eax
call   1050 <sortear@plt>
mov    $0x11,%edx
cmp    $0x5,%eax
jne    1230 <teste_sorteador+0xf0>
movsd  0xe1e(%rip),%xmm0
mov    $0x1,%al
call   1030 <set_random@plt>
mov    $0xa,%edi
xor    %eax,%eax
call   1050 <sortear@plt>
lea    0xe19(%rip),%rdi
mov    $0xa,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
xor    %eax,%eax
call   1050 <sortear@plt>
mov    $0x15,%edx
cmp    $0x6,%eax
je     124a <teste_sorteador+0x10a>
lea    0xe00(%rip),%rdi
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"rand() = %f\0A\00"
@.str.1 = [18 x i8] c"sortear(%d) = %d\0A\00"
@.str.2 = [26 x i8] c"\0Afailure in %s() line %d\0A\00"
@__func__.teste_sorteador = [16 x i8] c"teste_sorteador\00"
define i32 @teste_sorteador() {
%1 = alloca i32
%2 = call i32 (double, ...) bitcast (i32 (...)* @set_random to i32 (double, ...)*)(double 5.000000e-01)
%3 = call i32 (...) @rand()
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 10, i32 %5)
br label %7
7: ; preds = %0
%8 = call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%9 = icmp eq i32 %8, 5
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__func__.teste_sorteador, i64 0, i64 0), i32 13)
store i32 1, i32* %1
br label %34
12: ; preds = %7
br label %13
13: ; preds = %12
%14 = call i32 (double, ...) bitcast (i32 (...)* @set_random to i32 (double, ...)*)(double 5.400000e-01)
%15 = call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 10, i32 %15)
br label %17
17: ; preds = %13
%18 = call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%19 = icmp eq i32 %18, 5
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__func__.teste_sorteador, i64 0, i64 0), i32 17)
store i32 1, i32* %1
br label %34
22: ; preds = %17
br label %23
23: ; preds = %22
%24 = call i32 (double, ...) bitcast (i32 (...)* @set_random to i32 (double, ...)*)(double 5.600000e-01)
%25 = call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 10, i32 %25)
br label %27
27: ; preds = %23
%28 = call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%29 = icmp eq i32 %28, 6
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__func__.teste_sorteador, i64 0, i64 0), i32 21)
store i32 1, i32* %1
br label %34
32: ; preds = %27
br label %33
33: ; preds = %32
store i32 0, i32* %1
br label %34
34: ; preds = %33, %30, %20, %10
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [13 x i8] c"rand() = %f\0A\00"
@.str.1 = [18 x i8] c"sortear(%d) = %d\0A\00"
@.str.2 = [26 x i8] c"\0Afailure in %s() line %d\0A\00"
@__func__.teste_sorteador = [16 x i8] c"teste_sorteador\00"
define i32 @teste_sorteador() {
%1 = tail call i32 (double, ...) bitcast (i32 (...)* @set_random to i32 (double, ...)*)(double 5.000000e-01)
%2 = tail call i32 (...) @rand()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 10, i32 %4)
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%7 = icmp eq i32 %6, 5
br i1 %7, label %8, label %20
8: ; preds = %0
%9 = tail call i32 (double, ...) bitcast (i32 (...)* @set_random to i32 (double, ...)*)(double 5.400000e-01)
%10 = tail call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 10, i32 %10)
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%13 = icmp eq i32 %12, 5
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = tail call i32 (double, ...) bitcast (i32 (...)* @set_random to i32 (double, ...)*)(double 5.600000e-01)
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 10, i32 %16)
%18 = tail call i32 (i32, ...) bitcast (i32 (...)* @sortear to i32 (i32, ...)*)(i32 10)
%19 = icmp eq i32 %18, 6
br i1 %19, label %23, label %20
20: ; preds = %14, %8, %0
%21 = phi i32 [ 13, %0 ], [ 17, %8 ], [ 21, %14 ]
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @__func__.teste_sorteador, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %14
%24 = phi i32 [ 0, %14 ], [ 1, %20 ]
ret i32 %24
}