#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 *);
void *get_dimlen(char const *, char *);
int /*<<< orphan*/ get_file_dir(char const *, char *);
int /*<<< orphan*/ get_string_data_level(char const *, char *, char *,
                                         unsigned int *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
void read_mosaic_grid_sizes(const char *mosaic_file, int *nx, int *ny) {
  unsigned 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
jae    12d1 <read_mosaic_grid_sizes+0x181>
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
mov    -0x20(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
lea    -0x320(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1070 <get_dimlen@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1252 <read_mosaic_grid_sizes+0x102>
lea    0xdd0(%rip),%rdi
call   1050 <error_handler@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1279 <read_mosaic_grid_sizes+0x129>
lea    0xdea(%rip),%rdi
call   1050 <error_handler@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x20(%rbp),%ecx
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)
mov    -0x20(%rbp),%ecx
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>
mov    %rax,%r12
movl   $0x0,0xc(%rsp)
test   %r12d,%r12d
je     1272 <read_mosaic_grid_sizes+0x122>
lea    0x110(%rsp),%rbp
lea    0x210(%rsp),%r13
jmp    11e0 <read_mosaic_grid_sizes+0x90>
nopl   0x0(%rax)
mov    (%rbx,%rcx,4),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
mov    %edx,(%rbx,%rcx,4)
mov    (%r14,%rcx,4),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
mov    %edx,(%r14,%rcx,4)
add    $0x1,%ecx
mov    %ecx,0xc(%rsp)
cmp    %r12d,%ecx
jae    1272 <read_mosaic_grid_sizes+0x122>
mov    %r15,%rdi
lea    0xe1d(%rip),%rsi
mov    %rbp,%rdx
lea    0xc(%rsp),%rcx
call   1030 <get_string_data_level@plt>
mov    %r13,%rdi
lea    0xe10(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbp,%rcx
call   1060 <sprintf@plt>
mov    %r13,%rdi
lea    0xdff(%rip),%rsi
call   1070 <get_dimlen@plt>
mov    0xc(%rsp),%ecx
mov    %eax,(%rbx,%rcx,4)
mov    %r13,%rdi
lea    0xdec(%rip),%rsi
call   1070 <get_dimlen@plt>
mov    0xc(%rsp),%ecx
mov    %eax,(%r14,%rcx,4)
testb  $0x1,(%rbx,%rcx,4)
je     1255 <read_mosaic_grid_sizes+0x105>
lea    0xdd5(%rip),%rdi
call   1050 <error_handler@plt>
mov    0xc(%rsp),%ecx
mov    (%r14,%rcx,4),%eax
test   $0x1,%al
je     11b0 <read_mosaic_grid_sizes+0x60>
lea    0xdfa(%rip),%rdi
call   1050 <error_handler@plt>
mov    0xc(%rsp),%ecx
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 i8* @get_dimlen(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = ptrtoint i8* %18 to i32
store i32 %19, i32* %7
store i32 0, i32* %8
br label %20
20: ; preds = %78, %3
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %81
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%27 = call i32 @get_string_data_level(i8* %25, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32* %8)
%28 = getelementptr inbounds [510 x i8], [510 x i8]* %10, i64 0, i64 0
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%31 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %30)
%32 = getelementptr inbounds [510 x i8], [510 x i8]* %10, i64 0, i64 0
%33 = call i8* @get_dimlen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%34 = ptrtoint i8* %33 to i32
%35 = load i32*, i32** %5
%36 = load i32, i32* %8
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %34, i32* %38
%39 = getelementptr inbounds [510 x i8], [510 x i8]* %10, i64 0, i64 0
%40 = call i8* @get_dimlen(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%41 = ptrtoint i8* %40 to i32
%42 = load i32*, i32** %6
%43 = load i32, i32* %8
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
store i32 %41, i32* %45
%46 = load i32*, i32** %5
%47 = load i32, i32* %8
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
%50 = load i32, i32* %49
%51 = srem i32 %50, 2
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %24
%54 = call i32 @error_handler(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
br label %55
55: ; preds = %53, %24
%56 = load i32*, i32** %6
%57 = load i32, i32* %8
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = srem i32 %60, 2
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %55
%64 = call i32 @error_handler(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.6, i64 0, i64 0))
br label %65
65: ; preds = %63, %55
%66 = load i32*, i32** %5
%67 = load i32, i32* %8
%68 = zext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %66, i64 %68
%70 = load i32, i32* %69
%71 = sdiv i32 %70, 2
store i32 %71, i32* %69
%72 = load i32*, i32** %6
%73 = load i32, i32* %8
%74 = zext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %72, i64 %74
%76 = load i32, i32* %75
%77 = sdiv i32 %76, 2
store i32 %77, i32* %75
br label %78
78: ; preds = %65
%79 = load i32, i32* %8
%80 = add i32 %79, 1
store i32 %80, i32* %8
br label %20
81: ; preds = %20
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 i8* @get_dimlen(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = ptrtoint i8* %13 to i64
%15 = trunc i64 %14 to i32
store i32 0, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %63, label %17
17: ; preds = %3, %52
%18 = 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)
%19 = 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)
%20 = call i8* @get_dimlen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = ptrtoint i8* %20 to i64
%22 = trunc i64 %21 to i32
%23 = load i32, i32* %4
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %1, i64 %24
store i32 %22, i32* %25
%26 = call i8* @get_dimlen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = ptrtoint i8* %26 to i64
%28 = trunc i64 %27 to i32
%29 = load i32, i32* %4
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %2, i64 %30
store i32 %28, i32* %31
%32 = getelementptr inbounds i32, i32* %1, i64 %30
%33 = load i32, i32* %32
%34 = and i32 %33, 1
%35 = icmp eq i32 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %17
%37 = call i32 @error_handler(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* %4
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %2, i64 %39
%41 = load i32, i32* %40
br label %42
42: ; preds = %36, %17
%43 = phi i64 [ %39, %36 ], [ %30, %17 ]
%44 = phi i32 [ %41, %36 ], [ %28, %17 ]
%45 = phi i32 [ %38, %36 ], [ %29, %17 ]
%46 = and i32 %44, 1
%47 = icmp eq i32 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %42
%49 = call i32 @error_handler(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.6, i64 0, i64 0))
%50 = load i32, i32* %4
%51 = zext i32 %50 to i64
br label %52
52: ; preds = %48, %42
%53 = phi i64 [ %51, %48 ], [ %43, %42 ]
%54 = phi i32 [ %50, %48 ], [ %45, %42 ]
%55 = getelementptr inbounds i32, i32* %1, i64 %53
%56 = load i32, i32* %55
%57 = sdiv i32 %56, 2
store i32 %57, i32* %55
%58 = getelementptr inbounds i32, i32* %2, i64 %53
%59 = load i32, i32* %58
%60 = sdiv i32 %59, 2
store i32 %60, i32* %58
%61 = add i32 %54, 1
store i32 %61, i32* %4
%62 = icmp ult i32 %61, %15
br i1 %62, label %17, label %63
63: ; preds = %52, %3
ret void
}