#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*/ abort();
int /*<<< orphan*/ assert(int);
double atan(double);
int conv_angle_to_direc(double);
double cos(double);
int /*<<< orphan*/ free(char **);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
double sin(double);
int /*<<< orphan*/ take_next_step(char *, char *, int);
char *hpp_simulation(int dim, double r0, double r1, int nsteps) {
  assert(dim > 0);
  assert(nsteps >= 0);
  char(*oldlat)[dim] = (char(*)[dim])malloc(dim * dim * sizeof(char));
  char(*newlat)[dim] = (char(*)[dim])malloc(dim * dim * sizeof(char));
  if (oldlat == NULL || newlat == NULL) {
    perror("malloc (lattice)");
    abort();
  }
  double radius, angle;
  memset(oldlat, 0, dim * dim * sizeof(char));
  memset(newlat, 0, dim * dim * sizeof(char));
  for (radius = r0; radius < r1; radius += 0.5) {
    for (angle = 0; angle < 2 * (atan(1.0) * 4.0); angle += 0.5 / radius) {
      int direc = conv_angle_to_direc(angle);
      int x = radius * cos(angle) + dim / 2;
      int y = radius * sin(angle) + dim / 2;
      ((oldlat[y][x]) |= (1 << (direc)));
    }
  }
  int i;
  char(*tmp)[dim];
  for (i = 0; i < nsteps; i++) {
    take_next_step((char *)oldlat, (char *)newlat, dim);
    tmp = oldlat;
    oldlat = newlat;
    newlat = tmp;
  }
  free(newlat);
  return (char *)oldlat;
}


x86 assembly (clang, -O0):
<hpp_simulation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0x0,-0x1c(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x4(%rbp),%eax
mov    %rax,-0x60(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123a <hpp_simulation+0x8a>
cmpq   $0x0,-0x30(%rbp)
jne    124d <hpp_simulation+0x9d>
lea    0xddf(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    13cb <hpp_simulation+0x21b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xd57(%rip),%xmm0
call   1090 <atan@plt>
movsd  -0x68(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  0xd3a(%rip),%xmm0
mulsd  %xmm0,%xmm2
movsd  0xd26(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    13af <hpp_simulation+0x1ff>
movsd  -0x40(%rbp),%xmm0
call   10b0 <conv_angle_to_direc@plt>
mov    %eax,-0x44(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
call   10c0 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x78(%rbp),%xmm0
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1080 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x70(%rbp),%xmm0
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x60(%rbp),%rdx
cvtsi2sd %eax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    -0x28(%rbp),%rax
movslq -0x4c(%rbp),%rcx
imul   %rdx,%rcx
add    %rcx,%rax
movslq -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
or     %esi,%edx
mov    %dl,(%rax,%rcx,1)
movsd  0xc7d(%rip),%xmm0
divsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    12a7 <hpp_simulation+0xf7>
jmp    13b4 <hpp_simulation+0x204>
movsd  0xc5c(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    128b <hpp_simulation+0xdb>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1414 <hpp_simulation+0x264>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x4(%rbp),%edx
call   1050 <take_next_step@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    13d2 <hpp_simulation+0x222>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpp_simulation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,%r13d
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %edi,%ebx
xor    %edi,%edi
test   %ebx,%ebx
setg   %dil
call   1070 <assert@plt>
mov    %r13d,%edi
not    %edi
shr    $0x1f,%edi
call   1070 <assert@plt>
mov    %ebx,0x1c(%rsp)
imul   %ebx,%ebx
mov    %ebx,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   10a0 <malloc@plt>
test   %r15,%r15
je     13a6 <hpp_simulation+0x1f6>
mov    %rax,%r12
test   %rax,%rax
je     13a6 <hpp_simulation+0x1f6>
mov    %r15,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
movsd  0x20(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1361 <hpp_simulation+0x1b1>
mov    0x1c(%rsp),%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
sar    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x28(%rsp)
mov    %ecx,%ebp
movsd  0xd98(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
call   1090 <atan@plt>
movsd  0xd85(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x30(%rsp)
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
call   10b0 <conv_angle_to_direc@plt>
mov    %eax,%ebx
movsd  0x10(%rsp),%xmm0
call   10c0 <cos@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x28(%rsp),%xmm0
cvttsd2si %xmm0,%r14d
movsd  0x10(%rsp),%xmm0
call   1080 <sin@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x28(%rsp),%xmm0
cvttsd2si %xmm0,%eax
mov    $0x1,%edx
mov    %ebx,%ecx
shl    %cl,%edx
cltq
imul   %rbp,%rax
add    %r15,%rax
movslq %r14d,%rcx
or     %dl,(%rcx,%rax,1)
movsd  0x10(%rsp),%xmm0
addsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xce6(%rip),%xmm0
call   1090 <atan@plt>
movsd  0x10(%rsp),%xmm1
movsd  0xce3(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     12a0 <hpp_simulation+0xf0>
movsd  0xcc9(%rip),%xmm2
movsd  0x8(%rsp),%xmm1
addsd  %xmm2,%xmm1
movsd  0x20(%rsp),%xmm0
ucomisd %xmm1,%xmm0
movsd  0xca5(%rip),%xmm0
ja     1270 <hpp_simulation+0xc0>
test   %r13d,%r13d
jle    138c <hpp_simulation+0x1dc>
mov    %r15,%rax
mov    0x1c(%rsp),%ebx
nopl   (%rax)
mov    %r12,%r15
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <take_next_step@plt>
mov    %r15,%rax
add    $0xffffffff,%r13d
jne    1370 <hpp_simulation+0x1c0>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc6b(%rip),%rdi
call   10d0 <perror@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"malloc (lattice)\00"
define i8* @hpp_simulation(i32 %0, double %1, double %2, i32 %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
store i32 %0, i32* %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
%18 = load i32, i32* %5
%19 = icmp sgt i32 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %8
%23 = icmp sge i32 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %5
%27 = zext i32 %26 to i64
%28 = load i32, i32* %5
%29 = zext i32 %28 to i64
%30 = load i32, i32* %5
%31 = load i32, i32* %5
%32 = mul nsw i32 %30, %31
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 1
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %9
%38 = load i32, i32* %5
%39 = zext i32 %38 to i64
%40 = load i32, i32* %5
%41 = zext i32 %40 to i64
%42 = load i32, i32* %5
%43 = load i32, i32* %5
%44 = mul nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 1
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %10
%50 = load i8*, i8** %9
%51 = icmp eq i8* %50, null
br i1 %51, label %55, label %52
52: ; preds = %4
%53 = load i8*, i8** %10
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %58
55: ; preds = %52, %4
%56 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%57 = call i32 (...) @abort()
unreachable
58: ; preds = %52
%59 = load i8*, i8** %9
%60 = bitcast i8* %59 to i8**
%61 = load i32, i32* %5
%62 = load i32, i32* %5
%63 = mul nsw i32 %61, %62
%64 = sext i32 %63 to i64
%65 = mul i64 %64, 1
%66 = trunc i64 %65 to i32
%67 = call i32 @memset(i8** %60, i32 0, i32 %66)
%68 = load i8*, i8** %10
%69 = bitcast i8* %68 to i8**
%70 = load i32, i32* %5
%71 = load i32, i32* %5
%72 = mul nsw i32 %70, %71
%73 = sext i32 %72 to i64
%74 = mul i64 %73, 1
%75 = trunc i64 %74 to i32
%76 = call i32 @memset(i8** %69, i32 0, i32 %75)
%77 = load double, double* %6
store double %77, double* %11
br label %78
78: ; preds = %128, %58
%79 = load double, double* %11
%80 = load double, double* %7
%81 = fcmp olt double %79, %80
br i1 %81, label %82, label %131
82: ; preds = %78
store double 0.000000e+00, double* %12
br label %83
83: ; preds = %122, %82
%84 = load double, double* %12
%85 = call double @atan(double 1.000000e+00)
%86 = fmul double %85, 4.000000e+00
%87 = fmul double 2.000000e+00, %86
%88 = fcmp olt double %84, %87
br i1 %88, label %89, label %127
89: ; preds = %83
%90 = load double, double* %12
%91 = call i32 @conv_angle_to_direc(double %90)
store i32 %91, i32* %13
%92 = load double, double* %11
%93 = load double, double* %12
%94 = call double @cos(double %93)
%95 = load i32, i32* %5
%96 = sdiv i32 %95, 2
%97 = sitofp i32 %96 to double
%98 = call double @llvm.fmuladd.f64(double %92, double %94, double %97)
%99 = fptosi double %98 to i32
store i32 %99, i32* %14
%100 = load double, double* %11
%101 = load double, double* %12
%102 = call double @sin(double %101)
%103 = load i32, i32* %5
%104 = sdiv i32 %103, 2
%105 = sitofp i32 %104 to double
%106 = call double @llvm.fmuladd.f64(double %100, double %102, double %105)
%107 = fptosi double %106 to i32
store i32 %107, i32* %15
%108 = load i32, i32* %13
%109 = shl i32 1, %108
%110 = load i8*, i8** %9
%111 = load i32, i32* %15
%112 = sext i32 %111 to i64
%113 = mul nsw i64 %112, %27
%114 = getelementptr inbounds i8, i8* %110, i64 %113
%115 = load i32, i32* %14
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i8, i8* %114, i64 %116
%118 = load i8, i8* %117
%119 = sext i8 %118 to i32
%120 = or i32 %119, %109
%121 = trunc i32 %120 to i8
store i8 %121, i8* %117
br label %122
122: ; preds = %89
%123 = load double, double* %11
%124 = fdiv double 5.000000e-01, %123
%125 = load double, double* %12
%126 = fadd double %125, %124
store double %126, double* %12
br label %83
127: ; preds = %83
br label %128
128: ; preds = %127
%129 = load double, double* %11
%130 = fadd double %129, 5.000000e-01
store double %130, double* %11
br label %78
131: ; preds = %78
%132 = load i32, i32* %5
%133 = zext i32 %132 to i64
store i32 0, i32* %16
br label %134
134: ; preds = %146, %131
%135 = load i32, i32* %16
%136 = load i32, i32* %8
%137 = icmp slt i32 %135, %136
br i1 %137, label %138, label %149
138: ; preds = %134
%139 = load i8*, i8** %9
%140 = load i8*, i8** %10
%141 = load i32, i32* %5
%142 = call i32 @take_next_step(i8* %139, i8* %140, i32 %141)
%143 = load i8*, i8** %9
store i8* %143, i8** %17
%144 = load i8*, i8** %10
store i8* %144, i8** %9
%145 = load i8*, i8** %17
store i8* %145, i8** %10
br label %146
146: ; preds = %138
%147 = load i32, i32* %16
%148 = add nsw i32 %147, 1
store i32 %148, i32* %16
br label %134
149: ; preds = %134
%150 = load i8*, i8** %10
%151 = bitcast i8* %150 to i8**
%152 = call i32 @free(i8** %151)
%153 = load i8*, i8** %9
ret i8* %153
}

LLVM IR (-O2):
@.str = [17 x i8] c"malloc (lattice)\00"
define i8* @hpp_simulation(i32 %0, double %1, double %2, i32 %3) {
%5 = icmp sgt i32 %0, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = xor i32 %3, -1
%9 = lshr i32 %8, 31
%10 = tail call i32 @assert(i32 %9)
%11 = zext i32 %0 to i64
%12 = mul nsw i32 %0, %0
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i64 @malloc(i32 %12)
%16 = inttoptr i64 %15 to i8*
%17 = icmp eq i64 %13, 0
%18 = icmp eq i64 %15, 0
%19 = select i1 %17, i1 true, i1 %18
br i1 %19, label %20, label %23
20: ; preds = %4
%21 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 (...) @abort()
unreachable
23: ; preds = %4
%24 = inttoptr i64 %13 to i8**
%25 = tail call i32 @memset(i8** %24, i32 0, i32 %12)
%26 = inttoptr i64 %15 to i8**
%27 = tail call i32 @memset(i8** %26, i32 0, i32 %12)
%28 = fcmp olt double %1, %2
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = sdiv i32 %0, 2
%31 = sitofp i32 %30 to double
br label %32
32: ; preds = %29, %59
%33 = phi double [ %1, %29 ], [ %60, %59 ]
%34 = tail call double @atan(double 1.000000e+00)
%35 = fdiv double 5.000000e-01, %33
br label %38
36: ; preds = %59, %23
%37 = icmp sgt i32 %3, 0
br i1 %37, label %62, label %69
38: ; preds = %32, %38
%39 = phi double [ 0.000000e+00, %32 ], [ %56, %38 ]
%40 = tail call i32 @conv_angle_to_direc(double %39)
%41 = tail call double @cos(double %39)
%42 = tail call double @llvm.fmuladd.f64(double %33, double %41, double %31)
%43 = fptosi double %42 to i32
%44 = tail call double @sin(double %39)
%45 = tail call double @llvm.fmuladd.f64(double %33, double %44, double %31)
%46 = fptosi double %45 to i32
%47 = shl nuw i32 1, %40
%48 = sext i32 %46 to i64
%49 = mul nsw i64 %48, %11
%50 = getelementptr inbounds i8, i8* %14, i64 %49
%51 = sext i32 %43 to i64
%52 = getelementptr inbounds i8, i8* %50, i64 %51
%53 = load i8, i8* %52
%54 = trunc i32 %47 to i8
%55 = or i8 %53, %54
store i8 %55, i8* %52
%56 = fadd double %35, %39
%57 = tail call double @atan(double 1.000000e+00)
%58 = fcmp olt double %56, 0x401921FB54442D18
br i1 %58, label %38, label %59
59: ; preds = %38
%60 = fadd double %33, 5.000000e-01
%61 = fcmp olt double %60, %2
br i1 %61, label %32, label %36
62: ; preds = %36, %62
%63 = phi i8* [ %65, %62 ], [ %14, %36 ]
%64 = phi i32 [ %67, %62 ], [ 0, %36 ]
%65 = phi i8* [ %63, %62 ], [ %16, %36 ]
%66 = tail call i32 @take_next_step(i8* %63, i8* %65, i32 %0)
%67 = add nuw nsw i32 %64, 1
%68 = icmp eq i32 %67, %3
br i1 %68, label %69, label %62
69: ; preds = %62, %36
%70 = phi i8* [ %16, %36 ], [ %63, %62 ]
%71 = phi i8* [ %14, %36 ], [ %65, %62 ]
%72 = bitcast i8* %70 to i8**
%73 = tail call i32 @free(i8** %72)
ret i8* %71
}