#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*/ printf(char *, unsigned long long, unsigned int,
                          unsigned int, ...);
unsigned long long discrete_world_check_dimension_size(
    unsigned int nb_dimensions, unsigned int dimension_size[],
    unsigned int unit_size, unsigned int nb_previous_worlds) {
  unsigned long long nb_units = 0;
  unsigned int i = 0;
  unsigned long long unit_nb_type_max = 0;
  unit_nb_type_max--;
  if (nb_dimensions) {
    nb_units = dimension_size[0];
    for (i = 1; i < nb_dimensions; i++) {
      if (unit_nb_type_max / dimension_size[i] < nb_units) {
        printf("Number of world units cannot be stored on an UNIT_NB_TYPE "
               "(check discrete_world.h) :\n"
               "Current_size : %lld x (new_dimension %u) %u is too big (still "
               "%u dimensions to add including that one).\n"
               "Change your dimensions or storage data type. Peace.\n"
               "(I'm doing this for your own good.)\n",
               nb_units, i, dimension_size[i], nb_dimensions - i);
        return 0;
      }
      nb_units *= dimension_size[i];
    }
    if (unit_nb_type_max / (unit_size * nb_previous_worlds) < nb_units) {
      printf("Nope, this world RAM size won't fit into an UNIT_NB_TYPE (check "
             "discrete_world.h).\n"
             "(number of units) %lld x (size of unit) %u x %u (number of "
             "previous worlds) is too big.\n"
             "Please do something about it.\n",
             nb_units, unit_size, nb_previous_worlds);
      return 0;
    }
  }
  return nb_units;
}


x86 assembly (clang, -O0):
<discrete_world_check_dimension_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1227 <discrete_world_check_dimension_size+0x117>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11e1 <discrete_world_check_dimension_size+0xd1>
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x2c(%rbp),%edx
mov    (%rcx,%rdx,4),%ecx
xor    %edx,%edx
div    %rcx
cmp    -0x28(%rbp),%rax
jae    11c0 <discrete_world_check_dimension_size+0xb0>
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,4),%ecx
mov    -0xc(%rbp),%r8d
sub    -0x2c(%rbp),%r8d
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    122f <discrete_world_check_dimension_size+0x11f>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
imul   -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1163 <discrete_world_check_dimension_size+0x53>
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
mov    %ecx,%ecx
xor    %edx,%edx
div    %rcx
cmp    -0x28(%rbp),%rax
jae    1222 <discrete_world_check_dimension_size+0x112>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xf08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    122f <discrete_world_check_dimension_size+0x11f>
jmp    1227 <discrete_world_check_dimension_size+0x117>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<discrete_world_check_dimension_size>:
push   %rbx
test   %edi,%edi
je     1183 <discrete_world_check_dimension_size+0x73>
mov    %edx,%r9d
mov    (%rsi),%r11d
cmp    $0x1,%edi
je     1149 <discrete_world_check_dimension_size+0x39>
mov    %edi,%r8d
mov    $0x1,%r10d
nopl   0x0(%rax)
mov    (%rsi,%r10,4),%ebx
mov    %rbx,%rax
mul    %r11
jo     116a <discrete_world_check_dimension_size+0x5a>
imul   %rbx,%r11
add    $0x1,%r10
cmp    %r10,%r8
jne    1130 <discrete_world_check_dimension_size+0x20>
mov    %ecx,%eax
imul   %r9d,%eax
mul    %r11
jno    1186 <discrete_world_check_dimension_size+0x76>
lea    0xfbb(%rip),%rdi
mov    %r11,%rsi
mov    %r9d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1183 <discrete_world_check_dimension_size+0x73>
sub    %r10d,%r8d
lea    0xe8c(%rip),%rdi
mov    %r11,%rsi
mov    %r10d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %r11d,%r11d
mov    %r11,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [278 x i8] c"Number of world units cannot be stored on an UNIT_NB_TYPE (check discrete_world.h) :\0ACurrent_size : %lld x (new_dimension %u) %u is too big (still %u dimensions to add including that one).\0AChange your dimensions or storage data type. Peace.\0A(I'm doing this for your own good.)\0A\00"
@.str.1 = [202 x i8] c"Nope, this world RAM size won't fit into an UNIT_NB_TYPE (check discrete_world.h).\0A(number of units) %lld x (size of unit) %u x %u (number of previous worlds) is too big.\0APlease do something about it.\0A\00"
define i64 @discrete_world_check_dimension_size(i32 %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i64
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i64 0, i64* %10
store i32 0, i32* %11
store i64 0, i64* %12
%13 = load i64, i64* %12
%14 = add i64 %13, -1
store i64 %14, i64* %12
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %76
17: ; preds = %4
%18 = load i32*, i32** %7
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = zext i32 %20 to i64
store i64 %21, i64* %10
store i32 1, i32* %11
br label %22
22: ; preds = %58, %17
%23 = load i32, i32* %11
%24 = load i32, i32* %6
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %61
26: ; preds = %22
%27 = load i64, i64* %12
%28 = load i32*, i32** %7
%29 = load i32, i32* %11
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = zext i32 %32 to i64
%34 = udiv i64 %27, %33
%35 = load i64, i64* %10
%36 = icmp ult i64 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %26
%38 = load i64, i64* %10
%39 = load i32, i32* %11
%40 = load i32*, i32** %7
%41 = load i32, i32* %11
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %6
%46 = load i32, i32* %11
%47 = sub i32 %45, %46
%48 = call i32 (i8*, i64, i32, i32, ...) @printf(i8* getelementptr inbounds ([278 x i8], [278 x i8]* @.str, i64 0, i64 0), i64 %38, i32 %39, i32 %44, i32 %47)
store i64 0, i64* %5
br label %78
49: ; preds = %26
%50 = load i32*, i32** %7
%51 = load i32, i32* %11
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
%55 = zext i32 %54 to i64
%56 = load i64, i64* %10
%57 = mul i64 %56, %55
store i64 %57, i64* %10
br label %58
58: ; preds = %49
%59 = load i32, i32* %11
%60 = add i32 %59, 1
store i32 %60, i32* %11
br label %22
61: ; preds = %22
%62 = load i64, i64* %12
%63 = load i32, i32* %8
%64 = load i32, i32* %9
%65 = mul i32 %63, %64
%66 = zext i32 %65 to i64
%67 = udiv i64 %62, %66
%68 = load i64, i64* %10
%69 = icmp ult i64 %67, %68
br i1 %69, label %70, label %75
70: ; preds = %61
%71 = load i64, i64* %10
%72 = load i32, i32* %8
%73 = load i32, i32* %9
%74 = call i32 (i8*, i64, i32, i32, ...) @printf(i8* getelementptr inbounds ([202 x i8], [202 x i8]* @.str.1, i64 0, i64 0), i64 %71, i32 %72, i32 %73)
store i64 0, i64* %5
br label %78
75: ; preds = %61
br label %76
76: ; preds = %75, %4
%77 = load i64, i64* %10
store i64 %77, i64* %5
br label %78
78: ; preds = %76, %70, %37
%79 = load i64, i64* %5
ret i64 %79
}

LLVM IR (-O2):
@.str = [278 x i8] c"Number of world units cannot be stored on an UNIT_NB_TYPE (check discrete_world.h) :\0ACurrent_size : %lld x (new_dimension %u) %u is too big (still %u dimensions to add including that one).\0AChange your dimensions or storage data type. Peace.\0A(I'm doing this for your own good.)\0A\00"
@.str.1 = [202 x i8] c"Nope, this world RAM size won't fit into an UNIT_NB_TYPE (check discrete_world.h).\0A(number of units) %lld x (size of unit) %u x %u (number of previous worlds) is too big.\0APlease do something about it.\0A\00"
define i64 @discrete_world_check_dimension_size(i32 %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %0, 0
br i1 %5, label %36, label %6
6: ; preds = %4
%7 = load i32, i32* %1
%8 = zext i32 %7 to i64
%9 = icmp eq i32 %0, 1
br i1 %9, label %28, label %10
10: ; preds = %6
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %10, %24
%13 = phi i64 [ 1, %10 ], [ %26, %24 ]
%14 = phi i64 [ %8, %10 ], [ %25, %24 ]
%15 = getelementptr inbounds i32, i32* %1, i64 %13
%16 = load i32, i32* %15
%17 = zext i32 %16 to i64
%18 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %17, i64 %14)
%19 = extractvalue { i64, i1 } %18, 1
br i1 %19, label %20, label %24
20: ; preds = %12
%21 = trunc i64 %13 to i32
%22 = sub i32 %0, %21
%23 = tail call i32 (i8*, i64, i32, i32, ...) @printf(i8* getelementptr inbounds ([278 x i8], [278 x i8]* @.str, i64 0, i64 0), i64 %14, i32 %21, i32 %16, i32 %22)
br label %36
24: ; preds = %12
%25 = mul i64 %14, %17
%26 = add nuw nsw i64 %13, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %28, label %12
28: ; preds = %24, %6
%29 = phi i64 [ %8, %6 ], [ %25, %24 ]
%30 = mul i32 %3, %2
%31 = zext i32 %30 to i64
%32 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %31, i64 %29)
%33 = extractvalue { i64, i1 } %32, 1
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = tail call i32 (i8*, i64, i32, i32, ...) @printf(i8* getelementptr inbounds ([202 x i8], [202 x i8]* @.str.1, i64 0, i64 0), i64 %29, i32 %2, i32 %3)
br label %36
36: ; preds = %4, %28, %34, %20
%37 = phi i64 [ 0, %20 ], [ 0, %34 ], [ %29, %28 ], [ 0, %4 ]
ret i64 %37
}