#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 */
float drand48();
float fun(float);
int /*<<< orphan*/ print_array(float *, int);
float *reserva(int);
int /*<<< orphan*/ srand48(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  srand48(time(NULL));
  int n_iterations = 10000;
  int i;
  float a, r, xNew;
  float *x = reserva(n_iterations + 1);
  x[0] = 0;
  for (i = 0; i < n_iterations; i++) {
    xNew = x[i] + drand48() - 0.5;
    r = fun(xNew) / fun(x[i]);
    if (r > 1) {
      r = 1;
    }
    a = drand48();
    if (r > a) {
      x[i + 1] = xNew;
    } else {
      x[i + 1] = x[i];
    }
  }
  print_array(x, n_iterations + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1060 <srand48@plt>
movl   $0x2710,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1070 <reserva@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12b6 <main+0x156>
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1080 <drand48@plt>
movaps %xmm0,%xmm1
movss  -0x38(%rbp),%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe1d(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
call   1040 <fun@plt>
movss  %xmm0,-0x34(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1040 <fun@plt>
movaps %xmm0,%xmm1
movss  -0x34(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
movss  0xdc9(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    124d <main+0xed>
movss  0xdb8(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1080 <drand48@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x20(%rbp),%xmm0
ucomiss -0x1c(%rbp),%xmm0
jbe    1284 <main+0x124>
movss  -0x24(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    12a3 <main+0x143>
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    12a8 <main+0x148>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ae <main+0x4e>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1030 <print_array@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1060 <srand48@plt>
mov    $0x2711,%edi
call   1070 <reserva@plt>
mov    %rax,%r14
movl   $0x0,(%rax)
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    11a4 <main+0x44>
nopl   0x0(%rax)
movss  %xmm0,0x4(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0x2710,%rbx
je     1216 <main+0xb6>
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1080 <drand48@plt>
addss  0x4(%rsp),%xmm0
addss  0xe41(%rip),%xmm0
movss  %xmm0,0x4(%rsp)
call   1040 <fun@plt>
movss  %xmm0,(%rsp)
movss  (%r14,%rbx,4),%xmm0
call   1040 <fun@plt>
movss  (%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0xe19(%rip),%xmm0
minss  %xmm1,%xmm0
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1080 <drand48@plt>
movss  (%rsp),%xmm1
ucomiss %xmm0,%xmm1
movss  0x4(%rsp),%xmm0
ja     1190 <main+0x30>
movss  (%r14,%rbx,4),%xmm0
jmp    1190 <main+0x30>
mov    %r14,%rdi
mov    $0x2711,%esi
call   1030 <print_array@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @time(i32* null)
%13 = call i32 @srand48(i32 %12)
store i32 10000, i32* %6
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
%16 = call float* @reserva(i32 %15)
store float* %16, float** %11
%17 = load float*, float** %11
%18 = getelementptr inbounds float, float* %17, i64 0
store float 0.000000e+00, float* %18
store i32 0, i32* %7
br label %19
19: ; preds = %70, %2
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %73
23: ; preds = %19
%24 = load float*, float** %11
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds float, float* %24, i64 %26
%28 = load float, float* %27
%29 = call float (...) @drand48()
%30 = fadd float %28, %29
%31 = fpext float %30 to double
%32 = fsub double %31, 5.000000e-01
%33 = fptrunc double %32 to float
store float %33, float* %10
%34 = load float, float* %10
%35 = call float @fun(float %34)
%36 = load float*, float** %11
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds float, float* %36, i64 %38
%40 = load float, float* %39
%41 = call float @fun(float %40)
%42 = fdiv float %35, %41
store float %42, float* %9
%43 = load float, float* %9
%44 = fcmp ogt float %43, 1.000000e+00
br i1 %44, label %45, label %46
45: ; preds = %23
store float 1.000000e+00, float* %9
br label %46
46: ; preds = %45, %23
%47 = call float (...) @drand48()
store float %47, float* %8
%48 = load float, float* %9
%49 = load float, float* %8
%50 = fcmp ogt float %48, %49
br i1 %50, label %51, label %58
51: ; preds = %46
%52 = load float, float* %10
%53 = load float*, float** %11
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds float, float* %53, i64 %56
store float %52, float* %57
br label %69
58: ; preds = %46
%59 = load float*, float** %11
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds float, float* %59, i64 %61
%63 = load float, float* %62
%64 = load float*, float** %11
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds float, float* %64, i64 %67
store float %63, float* %68
br label %69
69: ; preds = %58, %51
br label %70
70: ; preds = %69
%71 = load i32, i32* %7
%72 = add nsw i32 %71, 1
store i32 %72, i32* %7
br label %19
73: ; preds = %19
%74 = load float*, float** %11
%75 = load i32, i32* %6
%76 = add nsw i32 %75, 1
%77 = call i32 @print_array(float* %74, i32 %76)
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand48(i32 %3)
%5 = tail call float* @reserva(i32 10001)
store float 0.000000e+00, float* %5
br label %6
6: ; preds = %23, %2
%7 = phi float [ 0.000000e+00, %2 ], [ %24, %23 ]
%8 = phi i64 [ 0, %2 ], [ %25, %23 ]
%9 = getelementptr inbounds float, float* %5, i64 %8
%10 = tail call float (...) @drand48()
%11 = fadd float %7, %10
%12 = fadd float %11, -5.000000e-01
%13 = tail call float @fun(float %12)
%14 = load float, float* %9
%15 = tail call float @fun(float %14)
%16 = fdiv float %13, %15
%17 = fcmp ogt float %16, 1.000000e+00
%18 = select i1 %17, float 1.000000e+00, float %16
%19 = tail call float (...) @drand48()
%20 = fcmp ogt float %18, %19
br i1 %20, label %23, label %21
21: ; preds = %6
%22 = load float, float* %9
br label %23
23: ; preds = %6, %21
%24 = phi float [ %22, %21 ], [ %12, %6 ]
%25 = add nuw nsw i64 %8, 1
%26 = getelementptr inbounds float, float* %5, i64 %25
store float %24, float* %26
%27 = icmp eq i64 %25, 10000
br i1 %27, label %28, label %6
28: ; preds = %23
%29 = tail call i32 @print_array(float* %5, i32 10001)
ret i32 0
}