#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int, float);
void save_ball_positions(char *filename, int *ballpos, int *ballradius,
                         int num_electrodes, int num_balls) {
  FILE *fl;
  float neutral_voltage = 0.5f;
  fl = fopen(filename, "w");
  for (int i = num_electrodes; i < num_electrodes + num_balls; i++) {
    fprintf(fl, "pos_ball; %i %i %i %f\n", ballpos[2 * i], ballpos[2 * i + 1],
            ballradius[i], neutral_voltage);
  }
  fclose(fl);
}


x86 assembly (clang, -O0):
<save_ball_positions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movss  0xead(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    11d5 <save_ball_positions+0xa5>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rsi
mov    (%rax,%rsi,4),%r8d
movss  -0x2c(%rbp),%xmm0
lea    0xe44(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1172 <save_ball_positions+0x42>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_ball_positions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r13d
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
test   %r13d,%r13d
jle    11a9 <save_ball_positions+0x79>
add    %r12d,%r13d
movslq %r12d,%rbp
movslq %r13d,%r13
lea    0x0(%rbp,%rbp,1),%r12d
nopl   0x0(%rax)
movslq %r12d,%r12
mov    (%rbx,%r12,4),%edx
lea    0x1(%r12),%eax
cltq
mov    (%rbx,%rax,4),%ecx
mov    (%r14,%rbp,4),%r8d
mov    %r15,%rdi
lea    0xe77(%rip),%rsi
movss  0xe69(%rip),%xmm0
call   1040 <fprintf@plt>
add    $0x1,%rbp
add    $0x2,%r12d
cmp    %r13,%rbp
jl     1170 <save_ball_positions+0x40>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [23 x i8] c"pos_ball; %i %i %i %f\0A\00"
define void @save_ball_positions(i8* %0, i32* %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca float
%13 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store float 5.000000e-01, float* %12
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %11
%16 = load i32, i32* %9
store i32 %16, i32* %13
br label %17
17: ; preds = %45, %5
%18 = load i32, i32* %13
%19 = load i32, i32* %9
%20 = load i32, i32* %10
%21 = add nsw i32 %19, %20
%22 = icmp slt i32 %18, %21
br i1 %22, label %23, label %48
23: ; preds = %17
%24 = load i32*, i32** %11
%25 = load i32*, i32** %7
%26 = load i32, i32* %13
%27 = mul nsw i32 2, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %25, i64 %28
%30 = load i32, i32* %29
%31 = load i32*, i32** %7
%32 = load i32, i32* %13
%33 = mul nsw i32 2, %32
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %31, i64 %35
%37 = load i32, i32* %36
%38 = load i32*, i32** %8
%39 = load i32, i32* %13
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = load float, float* %12
%44 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %37, i32 %42, float %43)
br label %45
45: ; preds = %23
%46 = load i32, i32* %13
%47 = add nsw i32 %46, 1
store i32 %47, i32* %13
br label %17
48: ; preds = %17
%49 = load i32*, i32** %11
%50 = call i32 @fclose(i32* %49)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [23 x i8] c"pos_ball; %i %i %i %f\0A\00"
define void @save_ball_positions(i8* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32 %3, i32 %4) {
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = add nsw i32 %4, %3
%10 = sext i32 %3 to i64
%11 = sext i32 %9 to i64
br label %14
12: ; preds = %14, %5
%13 = tail call i32 @fclose(i32* %6)
ret void
14: ; preds = %8, %14
%15 = phi i64 [ %10, %8 ], [ %28, %14 ]
%16 = trunc i64 %15 to i32
%17 = shl nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %1, i64 %18
%20 = load i32, i32* %19
%21 = or i32 %17, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %1, i64 %22
%24 = load i32, i32* %23
%25 = getelementptr inbounds i32, i32* %2, i64 %15
%26 = load i32, i32* %25
%27 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %24, i32 %26, float 5.000000e-01)
%28 = add nsw i64 %15, 1
%29 = icmp slt i64 %28, %11
br i1 %29, label %14, label %12
}