#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 */
scalar_t__ floor(double);
int /*<<< orphan*/ my_fatal(char *, char *, int);
double my_random_double();
int my_random_int(int n) {
  int r;
  {
    if (!(n > 0))
      my_fatal("file \"%s\", line %d, assertion \""
               "n>0"
               "\" failed\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/"
               "master/util.c",
               69);
  };
  r = ((int)floor(my_random_double() * ((double)n)));
  {
    if (!(r >= 0 && r < n))
      my_fatal("file \"%s\", line %d, assertion \""
               "r>=0&&r<n"
               "\" failed\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/"
               "master/util.c",
               72);
  };
  return r;
}


x86 assembly (clang, -O0):
<my_random_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     115d <my_random_int+0x2d>
lea    0xeb4(%rip),%rdi
lea    0xed9(%rip),%rsi
mov    $0x45,%edx
call   1040 <my_fatal@plt>
mov    $0x0,%al
call   1030 <my_random_double@plt>
cvtsi2sdl -0x4(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     118b <my_random_int+0x5b>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jl     11a3 <my_random_int+0x73>
lea    0xf1f(%rip),%rdi
lea    0xe93(%rip),%rsi
mov    $0x48,%edx
call   1040 <my_fatal@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_random_int>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
test   %edi,%edi
jg     1151 <my_random_int+0x21>
lea    0xec0(%rip),%rdi
lea    0xee5(%rip),%rsi
mov    $0x45,%edx
call   1040 <my_fatal@plt>
xor    %eax,%eax
call   1030 <my_random_double@plt>
cvtsi2sd %ebp,%xmm1
mulsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %rax,%rbx
test   %ebx,%ebx
js     1170 <my_random_int+0x40>
cmp    %ebp,%ebx
jl     1188 <my_random_int+0x58>
lea    0xf3a(%rip),%rdi
lea    0xeae(%rip),%rsi
mov    $0x48,%edx
call   1040 <my_fatal@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"file \22%s\22, line %d, assertion \22n>0\22 failed\0A\00"
@.str.1 = [133 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/master/util.c\00"
@.str.2 = [50 x i8] c"file \22%s\22, line %d, assertion \22r>=0&&r<n\22 failed\0A\00"
define i32 @my_random_int(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = call i32 @my_fatal(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0), i32 69)
br label %8
8: ; preds = %6, %1
%9 = call double (...) @my_random_double()
%10 = load i32, i32* %2
%11 = sitofp i32 %10 to double
%12 = fmul double %9, %11
%13 = call i64 @floor(double %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = load i32, i32* %3
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %23, label %21
21: ; preds = %17, %8
%22 = call i32 @my_fatal(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0), i32 72)
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [44 x i8] c"file \22%s\22, line %d, assertion \22n>0\22 failed\0A\00"
@.str.1 = [133 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ddugovic/polyglot/refs/heads/master/util.c\00"
@.str.2 = [50 x i8] c"file \22%s\22, line %d, assertion \22r>=0&&r<n\22 failed\0A\00"
define i32 @my_random_int(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i32 @my_fatal(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0), i32 69)
br label %5
5: ; preds = %3, %1
%6 = tail call double (...) @my_random_double()
%7 = sitofp i32 %0 to double
%8 = fmul double %6, %7
%9 = tail call i64 @floor(double %8)
%10 = trunc i64 %9 to i32
%11 = icmp sgt i32 %10, -1
%12 = icmp slt i32 %10, %0
%13 = and i1 %11, %12
br i1 %13, label %16, label %14
14: ; preds = %5
%15 = tail call i32 @my_fatal(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0), i32 72)
br label %16
16: ; preds = %5, %14
ret i32 %10
}