#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*/ drawline(int, int, int, int);
int /*<<< orphan*/ drawtext(int, int, char *);
int log10(double);
int /*<<< orphan*/ sprintf(char *, char *, int);
void draw_logscale(int ox, int oy, int axes_point_up) {
  int f, x, orient;
  double a;
  orient = (axes_point_up ? -1 : 1);
  for (f = 0, a = 1.; f <= 900; f++, a += 0.01) {
    x = (int)(log10(a) * (480 - 4 * 8));
    if (x >= (480 - 4 * 8))
      x = (480 - 4 * 8) - 1;
    x += ox;
    if (f < 100 && f % 2 == 0)
      drawline(x, oy, x, oy + orient * (1 - 1));
    if (f >= 100 && f < 4 * 100 && f % 5 == 0)
      drawline(x, oy, x, oy + orient * (1 - 1));
    if (f % 10 == 0)
      drawline(x, oy, x, oy + orient * (2 - 1));
    if (f % 50 == 0)
      drawline(x, oy, x, oy + orient * (3 - 1));
    if (f % 100 == 0) {
      static char buf[10];
      drawline(x, oy, x, oy + orient * (4 - 1));
      sprintf(buf, "%d", 1 + f / 100);
      drawtext(x - 1 - 2 * (f == 900),
               oy + orient * (4 - 1) + (orient == 1 ? 2 : -6), buf);
    }
  }
}


x86 assembly (clang, -O0):
<draw_logscale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
movsd  0xe8a(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x384,-0x10(%rbp)
jg     1340 <draw_logscale+0x200>
movsd  -0x20(%rbp),%xmm0
call   1040 <log10@plt>
imul   $0x1c0,%eax,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1c0,-0x14(%rbp)
jl     11af <draw_logscale+0x6f>
movl   $0x1bf,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x64,-0x10(%rbp)
jge    11ed <draw_logscale+0xad>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ed <draw_logscale+0xad>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   $0x0,-0x18(%rbp),%eax
add    %eax,%ecx
call   1060 <drawline@plt>
cmpl   $0x64,-0x10(%rbp)
jl     122f <draw_logscale+0xef>
cmpl   $0x190,-0x10(%rbp)
jge    122f <draw_logscale+0xef>
mov    -0x10(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    122f <draw_logscale+0xef>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   $0x0,-0x18(%rbp),%eax
add    %eax,%ecx
call   1060 <drawline@plt>
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    125c <draw_logscale+0x11c>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%eax
shl    $0x0,%eax
add    %eax,%ecx
call   1060 <drawline@plt>
mov    -0x10(%rbp),%eax
mov    $0x32,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1289 <draw_logscale+0x149>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
add    %eax,%ecx
call   1060 <drawline@plt>
mov    -0x10(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    131b <draw_logscale+0x1db>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   $0x3,-0x18(%rbp),%eax
add    %eax,%ecx
call   1060 <drawline@plt>
mov    -0x10(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
add    $0x1,%edx
lea    0x2d76(%rip),%rdi
lea    0xd3e(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
cmpl   $0x384,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
shl    $0x1,%eax
sub    %eax,%edi
mov    -0x8(%rbp),%esi
imul   $0x3,-0x18(%rbp),%eax
add    %eax,%esi
mov    -0x18(%rbp),%edx
mov    $0xfffffffa,%eax
mov    $0x2,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
add    %eax,%esi
lea    0x2d2b(%rip),%rdx
call   1030 <drawtext@plt>
jmp    1320 <draw_logscale+0x1e0>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movsd  0xcd7(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    117b <draw_logscale+0x3b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_logscale>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %edi,%r12d
xor    %eax,%eax
test   %edx,%edx
sete   %al
neg    %edx
sbb    %ecx,%ecx
or     $0x1,%ecx
lea    (%rbx,%rcx,2),%edx
mov    %edx,0x1c(%rsp)
lea    (%rcx,%rcx,2),%edx
add    %esi,%ecx
mov    %ecx,0x18(%rsp)
add    %esi,%edx
mov    %rdx,0x20(%rsp)
lea    (%rdx,%rax,8),%eax
add    $0xfffffffa,%eax
mov    %eax,0x14(%rsp)
xor    %r13d,%r13d
movsd  0xe73(%rip),%xmm0
mov    $0x1bf,%ebp
jmp    11b9 <draw_logscale+0x79>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13d
addsd  0xe5c(%rip),%xmm0
cmp    $0x385,%r13d
je     1301 <draw_logscale+0x1c1>
movsd  %xmm0,0x8(%rsp)
call   1040 <log10@plt>
imul   $0x1c0,%eax,%r14d
cmp    $0x1bf,%r14d
cmovge %ebp,%r14d
add    %r12d,%r14d
cmp    $0x63,%r13d
ja     11e7 <draw_logscale+0xa7>
mov    %r13d,%eax
and    $0x1,%eax
je     120f <draw_logscale+0xcf>
lea    -0x64(%r13),%eax
cmp    $0x12b,%eax
ja     121e <draw_logscale+0xde>
movzwl %r13w,%eax
imul   $0xcccd,%eax,%eax
shr    $0x12,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
movzwl %ax,%eax
add    %r13d,%eax
test   %ax,%ax
jne    121e <draw_logscale+0xde>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
call   1060 <drawline@plt>
movsd  0x8(%rsp),%xmm0
imul   $0xffffcccd,%r13d,%eax
ror    %ax
movzwl %ax,%eax
cmp    $0x1999,%eax
ja     124f <draw_logscale+0x10f>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %r14d,%edx
mov    0x18(%rsp),%ecx
call   1060 <drawline@plt>
movsd  0x8(%rsp),%xmm0
imul   $0x5c29,%r13d,%eax
ror    %ax
movzwl %ax,%eax
cmp    $0x51e,%eax
ja     127a <draw_logscale+0x13a>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %r14d,%edx
mov    0x1c(%rsp),%ecx
call   1060 <drawline@plt>
movsd  0x8(%rsp),%xmm0
movzwl %r13w,%eax
imul   $0x5c29,%eax,%ecx
ror    $0x2,%cx
movzwl %cx,%ecx
cmp    $0x28f,%ecx
ja     11a0 <draw_logscale+0x60>
shr    $0x2,%eax
imul   $0x147b,%eax,%r15d
shr    $0x11,%r15d
mov    %r14d,%edi
mov    %ebx,%esi
mov    %r14d,%edx
mov    0x20(%rsp),%rcx
call   1060 <drawline@plt>
movzwl %r15w,%edx
add    $0x1,%edx
lea    0x2d7c(%rip),%rbp
mov    %rbp,%rdi
lea    0xd41(%rip),%rsi
call   1050 <sprintf@plt>
xor    %eax,%eax
cmp    $0x384,%r13d
setne  %al
lea    -0x3(%r14,%rax,2),%edi
mov    0x14(%rsp),%esi
mov    %rbp,%rdx
mov    $0x1bf,%ebp
call   1030 <drawtext@plt>
movsd  0x8(%rsp),%xmm0
jmp    11a0 <draw_logscale+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@draw_logscale.buf = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define void @draw_logscale(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i32 -1, i32 1
store i32 %14, i32* %9
store i32 0, i32* %7
store double 1.000000e+00, double* %10
br label %15
15: ; preds = %124, %3
%16 = load i32, i32* %7
%17 = icmp sle i32 %16, 900
br i1 %17, label %18, label %129
18: ; preds = %15
%19 = load double, double* %10
%20 = call i32 @log10(double %19)
%21 = mul nsw i32 %20, 448
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp sge i32 %22, 448
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 447, i32* %8
br label %25
25: ; preds = %24, %18
%26 = load i32, i32* %4
%27 = load i32, i32* %8
%28 = add nsw i32 %27, %26
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 100
br i1 %30, label %31, label %44
31: ; preds = %25
%32 = load i32, i32* %7
%33 = srem i32 %32, 2
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = load i32, i32* %8
%37 = load i32, i32* %5
%38 = load i32, i32* %8
%39 = load i32, i32* %5
%40 = load i32, i32* %9
%41 = mul nsw i32 %40, 0
%42 = add nsw i32 %39, %41
%43 = call i32 @drawline(i32 %36, i32 %37, i32 %38, i32 %42)
br label %44
44: ; preds = %35, %31, %25
%45 = load i32, i32* %7
%46 = icmp sge i32 %45, 100
br i1 %46, label %47, label %63
47: ; preds = %44
%48 = load i32, i32* %7
%49 = icmp slt i32 %48, 400
br i1 %49, label %50, label %63
50: ; preds = %47
%51 = load i32, i32* %7
%52 = srem i32 %51, 5
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %63
54: ; preds = %50
%55 = load i32, i32* %8
%56 = load i32, i32* %5
%57 = load i32, i32* %8
%58 = load i32, i32* %5
%59 = load i32, i32* %9
%60 = mul nsw i32 %59, 0
%61 = add nsw i32 %58, %60
%62 = call i32 @drawline(i32 %55, i32 %56, i32 %57, i32 %61)
br label %63
63: ; preds = %54, %50, %47, %44
%64 = load i32, i32* %7
%65 = srem i32 %64, 10
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %76
67: ; preds = %63
%68 = load i32, i32* %8
%69 = load i32, i32* %5
%70 = load i32, i32* %8
%71 = load i32, i32* %5
%72 = load i32, i32* %9
%73 = mul nsw i32 %72, 1
%74 = add nsw i32 %71, %73
%75 = call i32 @drawline(i32 %68, i32 %69, i32 %70, i32 %74)
br label %76
76: ; preds = %67, %63
%77 = load i32, i32* %7
%78 = srem i32 %77, 50
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %89
80: ; preds = %76
%81 = load i32, i32* %8
%82 = load i32, i32* %5
%83 = load i32, i32* %8
%84 = load i32, i32* %5
%85 = load i32, i32* %9
%86 = mul nsw i32 %85, 2
%87 = add nsw i32 %84, %86
%88 = call i32 @drawline(i32 %81, i32 %82, i32 %83, i32 %87)
br label %89
89: ; preds = %80, %76
%90 = load i32, i32* %7
%91 = srem i32 %90, 100
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %123
93: ; preds = %89
%94 = load i32, i32* %8
%95 = load i32, i32* %5
%96 = load i32, i32* %8
%97 = load i32, i32* %5
%98 = load i32, i32* %9
%99 = mul nsw i32 %98, 3
%100 = add nsw i32 %97, %99
%101 = call i32 @drawline(i32 %94, i32 %95, i32 %96, i32 %100)
%102 = load i32, i32* %7
%103 = sdiv i32 %102, 100
%104 = add nsw i32 1, %103
%105 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @draw_logscale.buf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %104)
%106 = load i32, i32* %8
%107 = sub nsw i32 %106, 1
%108 = load i32, i32* %7
%109 = icmp eq i32 %108, 900
%110 = zext i1 %109 to i32
%111 = mul nsw i32 2, %110
%112 = sub nsw i32 %107, %111
%113 = load i32, i32* %5
%114 = load i32, i32* %9
%115 = mul nsw i32 %114, 3
%116 = add nsw i32 %113, %115
%117 = load i32, i32* %9
%118 = icmp eq i32 %117, 1
%119 = zext i1 %118 to i64
%120 = select i1 %118, i32 2, i32 -6
%121 = add nsw i32 %116, %120
%122 = call i32 @drawtext(i32 %112, i32 %121, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @draw_logscale.buf, i64 0, i64 0))
br label %123
123: ; preds = %93, %89
br label %124
124: ; preds = %123
%125 = load i32, i32* %7
%126 = add nsw i32 %125, 1
store i32 %126, i32* %7
%127 = load double, double* %10
%128 = fadd double %127, 1.000000e-02
store double %128, double* %10
br label %15
129: ; preds = %15
ret void
}

LLVM IR (-O2):
@draw_logscale.buf = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define void @draw_logscale(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
%5 = select i1 %4, i32 1, i32 -1
%6 = add nsw i32 %5, %1
%7 = shl nsw i32 %5, 1
%8 = add nsw i32 %7, %1
%9 = mul nsw i32 %5, 3
%10 = add nsw i32 %9, %1
%11 = select i1 %4, i32 2, i32 -6
%12 = add nsw i32 %10, %11
br label %13
13: ; preds = %3, %61
%14 = phi double [ 1.000000e+00, %3 ], [ %63, %61 ]
%15 = phi i32 [ 0, %3 ], [ %62, %61 ]
%16 = tail call i32 @log10(double %14)
%17 = mul nsw i32 %16, 448
%18 = icmp slt i32 %17, 447
%19 = select i1 %18, i32 %17, i32 447
%20 = add nsw i32 %19, %0
%21 = icmp ult i32 %15, 100
%22 = and i32 %15, 1
%23 = icmp eq i32 %22, 0
%24 = and i1 %21, %23
br i1 %24, label %25, label %28
25: ; preds = %13
%26 = tail call i32 @drawline(i32 %20, i32 %1, i32 %20, i32 %1)
%27 = trunc i32 %15 to i16
br label %37
28: ; preds = %13
%29 = add nsw i32 %15, -100
%30 = icmp ult i32 %29, 300
%31 = trunc i32 %15 to i16
%32 = urem i16 %31, 5
%33 = icmp eq i16 %32, 0
%34 = and i1 %30, %33
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = tail call i32 @drawline(i32 %20, i32 %1, i32 %20, i32 %1)
br label %37
37: ; preds = %25, %35, %28
%38 = phi i16 [ %27, %25 ], [ %31, %35 ], [ %31, %28 ]
%39 = urem i16 %38, 10
%40 = icmp eq i16 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = tail call i32 @drawline(i32 %20, i32 %1, i32 %20, i32 %6)
br label %43
43: ; preds = %41, %37
%44 = urem i16 %38, 50
%45 = icmp eq i16 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = tail call i32 @drawline(i32 %20, i32 %1, i32 %20, i32 %8)
br label %48
48: ; preds = %46, %43
%49 = urem i16 %38, 100
%50 = udiv i16 %38, 100
%51 = icmp eq i16 %49, 0
br i1 %51, label %52, label %61
52: ; preds = %48
%53 = tail call i32 @drawline(i32 %20, i32 %1, i32 %20, i32 %10)
%54 = add nuw nsw i16 %50, 1
%55 = zext i16 %54 to i32
%56 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @draw_logscale.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = icmp eq i32 %15, 900
%58 = select i1 %57, i32 -3, i32 -1
%59 = add i32 %58, %20
%60 = tail call i32 @drawtext(i32 %59, i32 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @draw_logscale.buf, i64 0, i64 0))
br label %61
61: ; preds = %48, %52
%62 = add nuw nsw i32 %15, 1
%63 = fadd double %14, 1.000000e-02
%64 = icmp eq i32 %62, 901
br i1 %64, label %65, label %13
65: ; preds = %61
ret void
}