#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*/ roadmap_square_set_screen_scale(int);
int roadmap_tile_get_max_scale();
int roadmap_tile_get_scale_factor(int);
void roadmap_square_adjust_scale(int zoom_factor) {
  int scale;
  int max_scale;
  max_scale = roadmap_tile_get_max_scale();
  for (scale = 1; scale <= max_scale &&
                  roadmap_tile_get_scale_factor(scale) <= zoom_factor;
       scale++)
    ;
  roadmap_square_set_screen_scale(scale - 1);
}


x86 assembly (clang, -O0):
<roadmap_square_adjust_scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <roadmap_tile_get_max_scale@plt>
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0xd(%rbp)
jg     116e <roadmap_square_adjust_scale+0x3e>
mov    -0x8(%rbp),%edi
call   1050 <roadmap_tile_get_scale_factor@plt>
cmp    -0x4(%rbp),%eax
setle  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    117e <roadmap_square_adjust_scale+0x4e>
jmp    1191 <roadmap_square_adjust_scale+0x61>
jmp    1183 <roadmap_square_adjust_scale+0x53>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114c <roadmap_square_adjust_scale+0x1c>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1030 <roadmap_square_set_screen_scale@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roadmap_square_adjust_scale>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
xor    %eax,%eax
call   1040 <roadmap_tile_get_max_scale@plt>
test   %eax,%eax
jle    1183 <roadmap_square_adjust_scale+0x53>
mov    %eax,%ebp
lea    0x1(%rbp),%r15d
neg    %ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
call   1050 <roadmap_tile_get_scale_factor@plt>
cmp    %r14d,%eax
jg     1188 <roadmap_square_adjust_scale+0x58>
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1160 <roadmap_square_adjust_scale+0x30>
mov    %r15d,%ebx
jmp    1188 <roadmap_square_adjust_scale+0x58>
mov    $0x1,%ebx
add    $0xffffffff,%ebx
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <roadmap_square_set_screen_scale@plt>

LLVM IR (-O0):
define void @roadmap_square_adjust_scale(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 (...) @roadmap_tile_get_max_scale()
store i32 %5, i32* %4
store i32 1, i32* %3
br label %6
6: ; preds = %18, %1
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = icmp sle i32 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* %3
%12 = call i32 @roadmap_tile_get_scale_factor(i32 %11)
%13 = load i32, i32* %2
%14 = icmp sle i32 %12, %13
br label %15
15: ; preds = %10, %6
%16 = phi i1 [ false, %6 ], [ %14, %10 ]
br i1 %16, label %17, label %21
17: ; preds = %15
br label %18
18: ; preds = %17
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %6
21: ; preds = %15
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, 1
%24 = call i32 @roadmap_square_set_screen_scale(i32 %23)
ret void
}

LLVM IR (-O2):
define void @roadmap_square_adjust_scale(i32 %0) {
%2 = tail call i32 (...) @roadmap_tile_get_max_scale()
%3 = icmp slt i32 %2, 1
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = add nuw i32 %2, 1
br label %6
6: ; preds = %4, %10
%7 = phi i32 [ %11, %10 ], [ 1, %4 ]
%8 = tail call i32 @roadmap_tile_get_scale_factor(i32 %7)
%9 = icmp sgt i32 %8, %0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = add nuw i32 %7, 1
%12 = icmp eq i32 %7, %2
br i1 %12, label %13, label %6
13: ; preds = %6, %10, %1
%14 = phi i32 [ 1, %1 ], [ %5, %10 ], [ %7, %6 ]
%15 = add nsw i32 %14, -1
%16 = tail call i32 @roadmap_square_set_screen_scale(i32 %15)
ret void
}