#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 M_PI;
scalar_t__ RAND_MAX;
float cos(float);
float fabs(float);
float fmod(float, double);
float rand();
float sin(float);
void random_walk(float *x, float magnitude, float half_w, float half_h,
                 float degrees) {
  float *y = x + 1;
  float *angle = x + 4;
  float *ct = x + 6;
  float *st = x + 7;
  if (fabs(*x) > half_w || fabs(*y) > half_h) {
    *angle = fmod(*angle + 180.0, 360.0);
  }
  float r = rand() / (float)(RAND_MAX);
  float rd = (r * 2 * degrees) - degrees;
  *angle = fmod(*angle + rd, 360.0);
  float theta = *angle / 180.0 * M_PI;
  *ct = cos(theta);
  *st = sin(theta);
  *x += magnitude * *ct;
  *y += magnitude * *st;
}


x86 assembly (clang, -O0):
<random_walk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
movss  %xmm3,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1c,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
call   1040 <fabs@plt>
ucomiss -0x10(%rbp),%xmm0
ja     11ce <random_walk+0x7e>
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm0
call   1040 <fabs@plt>
ucomiss -0x14(%rbp),%xmm0
jbe    11ff <random_walk+0xaf>
mov    -0x28(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe26(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movsd  0xe0e(%rip),%xmm1
call   1030 <fmod@plt>
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
mov    $0x0,%al
call   1070 <rand@plt>
mov    0x2dd3(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  0xded(%rip),%xmm0
mulss  -0x3c(%rbp),%xmm0
movss  -0x18(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movss  (%rax),%xmm0
addss  -0x40(%rbp),%xmm0
movsd  0xd9f(%rip),%xmm1
call   1030 <fmod@plt>
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd86(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    0x2d5b(%rip),%rax
movss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
call   1060 <cos@plt>
mov    -0x30(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x44(%rbp),%xmm0
call   1050 <sin@plt>
mov    -0x38(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0xc(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,(%rax)
movss  -0xc(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_walk>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm3,0x8(%rsp)
movss  %xmm0,0xc(%rsp)
mov    %rdi,%rbx
movss  (%rdi),%xmm0
andps  0xea1(%rip),%xmm0
ucomiss %xmm1,%xmm0
ja     1175 <random_walk+0x35>
movss  0x4(%rbx),%xmm0
andps  0xe90(%rip),%xmm0
ucomiss %xmm2,%xmm0
jbe    1194 <random_walk+0x54>
movss  0x10(%rbx),%xmm0
addss  0xe8e(%rip),%xmm0
movsd  0xe8e(%rip),%xmm1
call   1030 <fmod@plt>
movss  %xmm0,0x10(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    0x2e3e(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
addss  %xmm0,%xmm0
movss  0x8(%rsp),%xmm1
mulss  %xmm1,%xmm0
subss  %xmm1,%xmm0
addss  0x10(%rbx),%xmm0
movsd  0xe4b(%rip),%xmm1
call   1030 <fmod@plt>
movss  %xmm0,0x10(%rbx)
cvtss2sd %xmm0,%xmm0
divsd  0xe3d(%rip),%xmm0
mov    0x2dfe(%rip),%rax
movss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x8(%rsp)
call   1050 <cos@plt>
movss  %xmm0,0x18(%rbx)
movss  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,0x1c(%rbx)
movss  0x18(%rbx),%xmm1
movss  0xc(%rsp),%xmm2
mulss  %xmm2,%xmm1
addss  (%rbx),%xmm1
movss  %xmm1,(%rbx)
mulss  %xmm0,%xmm2
addss  0x4(%rbx),%xmm2
movss  %xmm2,0x4(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@M_PI = global float 0.000000e+00
define void @random_walk(float* %0, float %1, float %2, float %3, float %4) {
%6 = alloca float*
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float*
%12 = alloca float*
%13 = alloca float*
%14 = alloca float*
%15 = alloca float
%16 = alloca float
%17 = alloca float
store float* %0, float** %6
store float %1, float* %7
store float %2, float* %8
store float %3, float* %9
store float %4, float* %10
%18 = load float*, float** %6
%19 = getelementptr inbounds float, float* %18, i64 1
store float* %19, float** %11
%20 = load float*, float** %6
%21 = getelementptr inbounds float, float* %20, i64 4
store float* %21, float** %12
%22 = load float*, float** %6
%23 = getelementptr inbounds float, float* %22, i64 6
store float* %23, float** %13
%24 = load float*, float** %6
%25 = getelementptr inbounds float, float* %24, i64 7
store float* %25, float** %14
%26 = load float*, float** %6
%27 = load float, float* %26
%28 = call float @fabs(float %27)
%29 = load float, float* %8
%30 = fcmp ogt float %28, %29
br i1 %30, label %37, label %31
31: ; preds = %5
%32 = load float*, float** %11
%33 = load float, float* %32
%34 = call float @fabs(float %33)
%35 = load float, float* %9
%36 = fcmp ogt float %34, %35
br i1 %36, label %37, label %45
37: ; preds = %31, %5
%38 = load float*, float** %12
%39 = load float, float* %38
%40 = fpext float %39 to double
%41 = fadd double %40, 1.800000e+02
%42 = fptrunc double %41 to float
%43 = call float @fmod(float %42, double 3.600000e+02)
%44 = load float*, float** %12
store float %43, float* %44
br label %45
45: ; preds = %37, %31
%46 = call float (...) @rand()
%47 = load i64, i64* @RAND_MAX
%48 = sitofp i64 %47 to float
%49 = fdiv float %46, %48
store float %49, float* %15
%50 = load float, float* %15
%51 = fmul float %50, 2.000000e+00
%52 = load float, float* %10
%53 = load float, float* %10
%54 = fneg float %53
%55 = call float @llvm.fmuladd.f32(float %51, float %52, float %54)
store float %55, float* %16
%56 = load float*, float** %12
%57 = load float, float* %56
%58 = load float, float* %16
%59 = fadd float %57, %58
%60 = call float @fmod(float %59, double 3.600000e+02)
%61 = load float*, float** %12
store float %60, float* %61
%62 = load float*, float** %12
%63 = load float, float* %62
%64 = fpext float %63 to double
%65 = fdiv double %64, 1.800000e+02
%66 = load float, float* @M_PI
%67 = fpext float %66 to double
%68 = fmul double %65, %67
%69 = fptrunc double %68 to float
store float %69, float* %17
%70 = load float, float* %17
%71 = call float @cos(float %70)
%72 = load float*, float** %13
store float %71, float* %72
%73 = load float, float* %17
%74 = call float @sin(float %73)
%75 = load float*, float** %14
store float %74, float* %75
%76 = load float, float* %7
%77 = load float*, float** %13
%78 = load float, float* %77
%79 = load float*, float** %6
%80 = load float, float* %79
%81 = call float @llvm.fmuladd.f32(float %76, float %78, float %80)
store float %81, float* %79
%82 = load float, float* %7
%83 = load float*, float** %14
%84 = load float, float* %83
%85 = load float*, float** %11
%86 = load float, float* %85
%87 = call float @llvm.fmuladd.f32(float %82, float %84, float %86)
store float %87, float* %85
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@M_PI = global float 0.000000e+00
define void @random_walk(float* nocapture %0, float %1, float %2, float %3, float %4) {
%6 = getelementptr inbounds float, float* %0, i64 1
%7 = getelementptr inbounds float, float* %0, i64 4
%8 = getelementptr inbounds float, float* %0, i64 6
%9 = load float, float* %0
%10 = tail call float @llvm.fabs.f32(float %9)
%11 = fcmp ogt float %10, %2
br i1 %11, label %16, label %12
12: ; preds = %5
%13 = load float, float* %6
%14 = tail call float @llvm.fabs.f32(float %13)
%15 = fcmp ogt float %14, %3
br i1 %15, label %16, label %20
16: ; preds = %12, %5
%17 = load float, float* %7
%18 = fadd float %17, 1.800000e+02
%19 = tail call float @fmod(float %18, double 3.600000e+02)
store float %19, float* %7
br label %20
20: ; preds = %16, %12
%21 = getelementptr inbounds float, float* %0, i64 7
%22 = tail call float (...) @rand()
%23 = load i64, i64* @RAND_MAX
%24 = sitofp i64 %23 to float
%25 = fdiv float %22, %24
%26 = fmul float %25, 2.000000e+00
%27 = fneg float %4
%28 = tail call float @llvm.fmuladd.f32(float %26, float %4, float %27)
%29 = load float, float* %7
%30 = fadd float %29, %28
%31 = tail call float @fmod(float %30, double 3.600000e+02)
store float %31, float* %7
%32 = fpext float %31 to double
%33 = fdiv double %32, 1.800000e+02
%34 = load float, float* @M_PI
%35 = fpext float %34 to double
%36 = fmul double %33, %35
%37 = fptrunc double %36 to float
%38 = tail call float @cos(float %37)
store float %38, float* %8
%39 = tail call float @sin(float %37)
store float %39, float* %21
%40 = load float, float* %8
%41 = load float, float* %0
%42 = tail call float @llvm.fmuladd.f32(float %1, float %40, float %41)
store float %42, float* %0
%43 = load float, float* %6
%44 = tail call float @llvm.fmuladd.f32(float %1, float %39, float %43)
store float %44, float* %6
ret void
}