#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*/ error_handler(char *);
int get_dimlen(char const *, char *);
int /*<<< orphan*/ get_file_dir(char const *, char *);
int /*<<< orphan*/ get_string_data_level(char const *, char *, char *, int *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
void read_mosaic_grid_sizes(const char *mosaic_file, int *nx, int *ny) {
  int ntiles, n;
  char gridfile[255], tilefile[2 * 255];
  char dir[255];
  const int x_refine = 2, y_refine = 2;
  get_file_dir(mosaic_file, dir);
  ntiles = get_dimlen(mosaic_file, "ntiles");
  for (n = 0; n < ntiles; n++) {
    get_string_data_level(mosaic_file, "gridfiles", gridfile, &n);
    sprintf(tilefile, "%s/%s", dir, gridfile);
    nx[n] = get_dimlen(tilefile, "nx");
    ny[n] = get_dimlen(tilefile, "ny");
    if (nx[n] % x_refine != 0)
      error_handler(
          "Error from read_mosaic_grid_sizes: nx is not divided by x_refine");
    if (ny[n] % y_refine != 0)
      error_handler(
          "Error from read_mosaic_grid_sizes: ny is not divided by y_refine");
    nx[n] /= x_refine;
    ny[n] /= y_refine;
  }
}


x86 assembly (clang, -O0):
<read_mosaic_grid_sizes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x2,-0x424(%rbp)
movl   $0x2,-0x428(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1040 <get_file_dir@plt>
mov    -0x8(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <get_dimlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12d7 <read_mosaic_grid_sizes+0x187>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe44(%rip),%rsi
lea    -0x20(%rbp),%rcx
call   1030 <get_string_data_level@plt>
lea    -0x320(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    -0x120(%rbp),%rcx
lea    0xe29(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x320(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1070 <get_dimlen@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    -0x320(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1070 <get_dimlen@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1255 <read_mosaic_grid_sizes+0x105>
lea    0xdcd(%rip),%rdi
call   1050 <error_handler@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     127d <read_mosaic_grid_sizes+0x12d>
lea    0xde6(%rip),%rdi
call   1050 <error_handler@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x438(%rbp)
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x438(%rbp),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    %rax,-0x430(%rbp)
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x430(%rbp),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a5 <read_mosaic_grid_sizes+0x55>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_mosaic_grid_sizes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x10(%rsp),%rsi
call   1040 <get_file_dir@plt>
lea    0xe85(%rip),%rsi
mov    %r15,%rdi
call   1070 <get_dimlen@plt>
movl   $0x0,0xc(%rsp)
test   %eax,%eax
jle    127b <read_mosaic_grid_sizes+0x12b>
mov    %eax,%ebp
lea    0x110(%rsp),%r13
lea    0x210(%rsp),%r12
jmp    11df <read_mosaic_grid_sizes+0x8f>
nopw   0x0(%rax,%rax,1)
mov    (%rbx,%rdx,4),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
mov    %esi,(%rbx,%rdx,4)
mov    (%r14,%rdx,4),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
mov    %esi,(%r14,%rdx,4)
add    $0x1,%ecx
mov    %ecx,0xc(%rsp)
cmp    %ebp,%ecx
jge    127b <read_mosaic_grid_sizes+0x12b>
mov    %r15,%rdi
lea    0xe1e(%rip),%rsi
mov    %r13,%rdx
lea    0xc(%rsp),%rcx
call   1030 <get_string_data_level@plt>
mov    %r12,%rdi
lea    0xe11(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r13,%rcx
call   1060 <sprintf@plt>
mov    %r12,%rdi
lea    0xe00(%rip),%rsi
call   1070 <get_dimlen@plt>
movslq 0xc(%rsp),%rcx
mov    %eax,(%rbx,%rcx,4)
mov    %r12,%rdi
lea    0xdec(%rip),%rsi
call   1070 <get_dimlen@plt>
mov    0xc(%rsp),%ecx
movslq %ecx,%rdx
mov    %eax,(%r14,%rdx,4)
testb  $0x1,(%rbx,%rdx,4)
je     125b <read_mosaic_grid_sizes+0x10b>
lea    0xdd2(%rip),%rdi
call   1050 <error_handler@plt>
mov    0xc(%rsp),%ecx
movslq %ecx,%rdx
mov    (%r14,%rdx,4),%eax
test   $0x1,%al
je     11b0 <read_mosaic_grid_sizes+0x60>
lea    0xdf4(%rip),%rdi
call   1050 <error_handler@plt>
mov    0xc(%rsp),%ecx
movslq %ecx,%rdx
jmp    11b0 <read_mosaic_grid_sizes+0x60>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"ntiles\00"
@.str.1 = [10 x i8] c"gridfiles\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [3 x i8] c"nx\00"
@.str.4 = [3 x i8] c"ny\00"
@.str.5 = [65 x i8] c"Error from read_mosaic_grid_sizes: nx is not divided by x_refine\00"
@.str.6 = [65 x i8] c"Error from read_mosaic_grid_sizes: ny is not divided by y_refine\00"
define void @read_mosaic_grid_sizes(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [255 x i8]
%10 = alloca [510 x i8]
%11 = alloca [255 x i8]
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 2, i32* %12
store i32 2, i32* %13
%14 = load i8*, i8** %4
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%16 = call i32 @get_file_dir(i8* %14, i8* %15)
%17 = load i8*, i8** %4
%18 = call i32 @get_dimlen(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %7
store i32 0, i32* %8
br label %19
19: ; preds = %75, %3
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %78
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%26 = call i32 @get_string_data_level(i8* %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32* %8)
%27 = getelementptr inbounds [510 x i8], [510 x i8]* %10, i64 0, i64 0
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%30 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %28, i8* %29)
%31 = getelementptr inbounds [510 x i8], [510 x i8]* %10, i64 0, i64 0
%32 = call i32 @get_dimlen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32*, i32** %5
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
%37 = getelementptr inbounds [510 x i8], [510 x i8]* %10, i64 0, i64 0
%38 = call i32 @get_dimlen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32*, i32** %6
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 %38, i32* %42
%43 = load i32*, i32** %5
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = srem i32 %47, 2
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %23
%51 = call i32 @error_handler(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %50, %23
%53 = load i32*, i32** %6
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = srem i32 %57, 2
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %52
%61 = call i32 @error_handler(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %60, %52
%63 = load i32*, i32** %5
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = sdiv i32 %67, 2
store i32 %68, i32* %66
%69 = load i32*, i32** %6
%70 = load i32, i32* %8
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %69, i64 %71
%73 = load i32, i32* %72
%74 = sdiv i32 %73, 2
store i32 %74, i32* %72
br label %75
75: ; preds = %62
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %19
78: ; preds = %19
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"ntiles\00"
@.str.1 = [10 x i8] c"gridfiles\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [3 x i8] c"nx\00"
@.str.4 = [3 x i8] c"ny\00"
@.str.5 = [65 x i8] c"Error from read_mosaic_grid_sizes: nx is not divided by x_refine\00"
@.str.6 = [65 x i8] c"Error from read_mosaic_grid_sizes: ny is not divided by y_refine\00"
define void @read_mosaic_grid_sizes(i8* %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca i32
%5 = alloca [255 x i8]
%6 = alloca [510 x i8]
%7 = alloca [255 x i8]
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [510 x i8], [510 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%12 = call i32 @get_file_dir(i8* %0, i8* %11)
%13 = call i32 @get_dimlen(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %57
15: ; preds = %3, %46
%16 = call i32 @get_string_data_level(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32* %4)
%17 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %9)
%18 = call i32 @get_dimlen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %1, i64 %20
store i32 %18, i32* %21
%22 = call i32 @get_dimlen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %2, i64 %24
store i32 %22, i32* %25
%26 = getelementptr inbounds i32, i32* %1, i64 %24
%27 = load i32, i32* %26
%28 = and i32 %27, 1
%29 = icmp eq i32 %28, 0
br i1 %29, label %36, label %30
30: ; preds = %15
%31 = call i32 @error_handler(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %2, i64 %33
%35 = load i32, i32* %34
br label %36
36: ; preds = %30, %15
%37 = phi i64 [ %33, %30 ], [ %24, %15 ]
%38 = phi i32 [ %35, %30 ], [ %22, %15 ]
%39 = phi i32 [ %32, %30 ], [ %23, %15 ]
%40 = and i32 %38, 1
%41 = icmp eq i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %36
%43 = call i32 @error_handler(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.6, i64 0, i64 0))
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
br label %46
46: ; preds = %42, %36
%47 = phi i64 [ %45, %42 ], [ %37, %36 ]
%48 = phi i32 [ %44, %42 ], [ %39, %36 ]
%49 = getelementptr inbounds i32, i32* %1, i64 %47
%50 = load i32, i32* %49
%51 = sdiv i32 %50, 2
store i32 %51, i32* %49
%52 = getelementptr inbounds i32, i32* %2, i64 %47
%53 = load i32, i32* %52
%54 = sdiv i32 %53, 2
store i32 %54, i32* %52
%55 = add nsw i32 %48, 1
store i32 %55, i32* %4
%56 = icmp slt i32 %55, %13
br i1 %56, label %15, label %57
57: ; preds = %46, %3
ret void
}