#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 */
struct RYUON_grid {
  int dummy;
};

/* Variables and functions */
scalar_t__ GRID_add_particle(struct RYUON_grid *, double const *, int);
int /*<<< orphan*/ GRID_clear(struct RYUON_grid *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
void GRID_assign_particles(struct RYUON_grid *g, int np, const double *x) {
  GRID_clear(g);
  int i;
  for (i = 0; i < np; i++) {
    int ix = i * 3;
    if (GRID_add_particle(g, x + ix, i) == 0) {
      fprintf(stderr,
              "GRID_assign_particles():"
              "fail to assign particle %d\n",
              i);
    }
  }
}


x86 assembly (clang, -O0):
<GRID_assign_particles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <GRID_clear@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b6 <GRID_assign_particles+0x86>
imul   $0x3,-0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1040 <GRID_add_particle@plt>
cmp    $0x0,%rax
jne    11a3 <GRID_assign_particles+0x73>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe62(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11a8 <GRID_assign_particles+0x78>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <GRID_assign_particles+0x23>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GRID_assign_particles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <GRID_clear@plt>
test   %ebx,%ebx
jle    119e <GRID_assign_particles+0x6e>
mov    %ebx,%r13d
xor    %ebx,%ebx
mov    0x2e88(%rip),%rbp
lea    0xea1(%rip),%r12
jmp    117d <GRID_assign_particles+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0x18,%r15
cmp    %rbx,%r13
je     119e <GRID_assign_particles+0x6e>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <GRID_add_particle@plt>
test   %rax,%rax
jne    1170 <GRID_assign_particles+0x40>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
jmp    1170 <GRID_assign_particles+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.RYUON_grid = type { i32 }
@stderr = global i32 0
@.str = [52 x i8] c"GRID_assign_particles():fail to assign particle %d\0A\00"
define void @GRID_assign_particles(%struct.RYUON_grid* %0, i32 %1, double* %2) {
%4 = alloca %struct.RYUON_grid*
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
store %struct.RYUON_grid* %0, %struct.RYUON_grid** %4
store i32 %1, i32* %5
store double* %2, double** %6
%9 = load %struct.RYUON_grid*, %struct.RYUON_grid** %4
%10 = call i32 @GRID_clear(%struct.RYUON_grid* %9)
store i32 0, i32* %7
br label %11
11: ; preds = %31, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load i32, i32* %7
%17 = mul nsw i32 %16, 3
store i32 %17, i32* %8
%18 = load %struct.RYUON_grid*, %struct.RYUON_grid** %4
%19 = load double*, double** %6
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load i32, i32* %7
%24 = call i64 @GRID_add_particle(%struct.RYUON_grid* %18, double* %22, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %15
%27 = load i32, i32* @stderr
%28 = load i32, i32* %7
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26, %15
br label %31
31: ; preds = %30
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %11
34: ; preds = %11
ret void
}

LLVM IR (-O2):
%struct.RYUON_grid = type { i32 }
@stderr = global i32 0
@.str = [52 x i8] c"GRID_assign_particles():fail to assign particle %d\0A\00"
define void @GRID_assign_particles(%struct.RYUON_grid* %0, i32 %1, double* %2) {
%4 = tail call i32 @GRID_clear(%struct.RYUON_grid* %0)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %18
%9 = phi i64 [ 0, %6 ], [ %19, %18 ]
%10 = mul nuw nsw i64 %9, 3
%11 = getelementptr inbounds double, double* %2, i64 %10
%12 = trunc i64 %9 to i32
%13 = tail call i64 @GRID_add_particle(%struct.RYUON_grid* %0, double* %11, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %18
18: ; preds = %15, %8
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %18, %3
ret void
}