#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*/ strcpy(char *, char *);
void unpackgrid(int ngrid, char *grid) {
  char c[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
              'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
              'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' '};
  int dlat, dlong;
  ngrid = ngrid >> 7;
  if (ngrid < 32400) {
    dlat = (ngrid % 180) - 90;
    dlong = (ngrid / 180) * 2 - 180 + 2;
    if (dlong < -180)
      dlong = dlong + 360;
    if (dlong > 180)
      dlong = dlong + 360;
    int nlong = 60.0 * (180.0 - dlong) / 5.0;
    int n1 = nlong / 240;
    int n2 = (nlong - 240 * n1) / 24;
    grid[0] = c[10 + n1];
    grid[2] = c[n2];
    int nlat = 60.0 * (dlat + 90) / 2.5;
    n1 = nlat / 240;
    n2 = (nlat - 240 * n1) / 24;
    grid[1] = c[10 + n1];
    grid[3] = c[n2];
  } else {
    strcpy(grid, "XXXX");
  }
}


x86 assembly (clang, -O0):
<unpackgrid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xee6(%rip),%rsi
mov    $0x25,%edx
call   1040 <memcpy@plt>
mov    -0x4(%rbp),%eax
sar    $0x7,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x7e90,-0x4(%rbp)
jge    129f <unpackgrid+0x17f>
mov    -0x4(%rbp),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
sub    $0x5a,%edx
mov    %edx,-0x44(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
shl    $0x1,%eax
sub    $0xb4,%eax
add    $0x2,%eax
mov    %eax,-0x48(%rbp)
cmpl   $0xffffff4c,-0x48(%rbp)
jge    119c <unpackgrid+0x7c>
mov    -0x48(%rbp),%eax
add    $0x168,%eax
mov    %eax,-0x48(%rbp)
cmpl   $0xb4,-0x48(%rbp)
jle    11b4 <unpackgrid+0x94>
mov    -0x48(%rbp),%eax
add    $0x168,%eax
mov    %eax,-0x48(%rbp)
cvtsi2sdl -0x48(%rbp),%xmm0
movsd  0xe57(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  0xe3b(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe37(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    $0xf0,%ecx
cltd
idiv   %ecx
mov    %eax,-0x50(%rbp)
mov    -0x4c(%rbp),%eax
imul   $0xf0,-0x50(%rbp),%ecx
sub    %ecx,%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%eax
add    $0xa,%eax
cltq
mov    -0x40(%rbp,%rax,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movslq -0x54(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x44(%rbp),%eax
add    $0x5a,%eax
cvtsi2sd %eax,%xmm1
movsd  0xdcc(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdb8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    $0xf0,%ecx
cltd
idiv   %ecx
mov    %eax,-0x50(%rbp)
mov    -0x58(%rbp),%eax
imul   $0xf0,-0x50(%rbp),%ecx
sub    %ecx,%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%eax
add    $0xa,%eax
cltq
mov    -0x40(%rbp,%rax,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
movslq -0x54(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
jmp    12af <unpackgrid+0x18f>
mov    -0x10(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpackgrid>:
cmp    $0x3f47ff,%edi
jg     1238 <unpackgrid+0x128>
mov    %edi,%eax
sar    $0x7,%eax
cltq
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
imul   $0xb4,%ecx,%edx
sub    %edx,%eax
cmp    $0xffff4c80,%edi
lea    0xb6(%rcx,%rcx,1),%edx
lea    -0xb2(%rcx,%rcx,1),%ecx
cmovl  %edx,%ecx
cvtsi2sd %ecx,%xmm0
movsd  0xe9b(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  0xe97(%rip),%xmm0
mulsd  %xmm0,%xmm1
divsd  0xe93(%rip),%xmm1
cvttsd2si %xmm1,%ecx
movslq %ecx,%rcx
imul   $0xffffffff88888889,%rcx,%rdx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%edi
shr    $0x1f,%edi
sar    $0x7,%edx
add    %edi,%edx
imul   $0xffffff10,%edx,%edi
add    %ecx,%edi
movslq %edi,%rcx
imul   $0x2aaaaaab,%rcx,%rdi
mov    %rdi,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdi
sar    $0x2,%edi
add    %ecx,%edi
movslq %edx,%rdx
lea    0xe59(%rip),%rcx
mov    0xa(%rdx,%rcx,1),%dl
mov    %dl,(%rsi)
movslq %edi,%rdx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x2(%rsi)
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  %xmm0,%xmm1
divsd  0xe2f(%rip),%xmm1
cvttsd2si %xmm1,%eax
cltq
imul   $0xffffffff88888889,%rax,%rdx
shr    $0x20,%rdx
add    %eax,%edx
mov    %edx,%edi
shr    $0x1f,%edi
sar    $0x7,%edx
add    %edi,%edx
imul   $0xffffff10,%edx,%edi
add    %eax,%edi
movslq %edi,%rax
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rax
add    %edi,%eax
movslq %edx,%rdx
mov    0xa(%rdx,%rcx,1),%dl
mov    %dl,0x1(%rsi)
cltq
mov    (%rax,%rcx,1),%al
mov    %al,0x3(%rsi)
ret
lea    0xe06(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@__const.unpackgrid.c = [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "
@.str = [5 x i8] c"XXXX\00"
define void @unpackgrid(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [37 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%12 = bitcast [37 x i8]* %5 to i8*
%13 = load i32, i32* %3
%14 = ashr i32 %13, 7
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 32400
br i1 %16, label %17, label %90
17: ; preds = %2
%18 = load i32, i32* %3
%19 = srem i32 %18, 180
%20 = sub nsw i32 %19, 90
store i32 %20, i32* %6
%21 = load i32, i32* %3
%22 = sdiv i32 %21, 180
%23 = mul nsw i32 %22, 2
%24 = sub nsw i32 %23, 180
%25 = add nsw i32 %24, 2
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, -180
br i1 %27, label %28, label %31
28: ; preds = %17
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 360
store i32 %30, i32* %7
br label %31
31: ; preds = %28, %17
%32 = load i32, i32* %7
%33 = icmp sgt i32 %32, 180
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 360
store i32 %36, i32* %7
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %7
%39 = sitofp i32 %38 to double
%40 = fsub double 1.800000e+02, %39
%41 = fmul double 6.000000e+01, %40
%42 = fdiv double %41, 5.000000e+00
%43 = fptosi double %42 to i32
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = sdiv i32 %44, 240
store i32 %45, i32* %9
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = mul nsw i32 240, %47
%49 = sub nsw i32 %46, %48
%50 = sdiv i32 %49, 24
store i32 %50, i32* %10
%51 = load i32, i32* %9
%52 = add nsw i32 10, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [37 x i8], [37 x i8]* %5, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = load i8*, i8** %4
%57 = getelementptr inbounds i8, i8* %56, i64 0
store i8 %55, i8* %57
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [37 x i8], [37 x i8]* %5, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = load i8*, i8** %4
%63 = getelementptr inbounds i8, i8* %62, i64 2
store i8 %61, i8* %63
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 90
%66 = sitofp i32 %65 to double
%67 = fmul double 6.000000e+01, %66
%68 = fdiv double %67, 2.500000e+00
%69 = fptosi double %68 to i32
store i32 %69, i32* %11
%70 = load i32, i32* %11
%71 = sdiv i32 %70, 240
store i32 %71, i32* %9
%72 = load i32, i32* %11
%73 = load i32, i32* %9
%74 = mul nsw i32 240, %73
%75 = sub nsw i32 %72, %74
%76 = sdiv i32 %75, 24
store i32 %76, i32* %10
%77 = load i32, i32* %9
%78 = add nsw i32 10, %77
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [37 x i8], [37 x i8]* %5, i64 0, i64 %79
%81 = load i8, i8* %80
%82 = load i8*, i8** %4
%83 = getelementptr inbounds i8, i8* %82, i64 1
store i8 %81, i8* %83
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [37 x i8], [37 x i8]* %5, i64 0, i64 %85
%87 = load i8, i8* %86
%88 = load i8*, i8** %4
%89 = getelementptr inbounds i8, i8* %88, i64 3
store i8 %87, i8* %89
br label %93
90: ; preds = %2
%91 = load i8*, i8** %4
%92 = call i32 @strcpy(i8* %91, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %93
93: ; preds = %90, %37
ret void
}

LLVM IR (-O2):
@__const.unpackgrid.c = [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "
@.str = [5 x i8] c"XXXX\00"
define void @unpackgrid(i32 %0, i8* %1) {
%3 = ashr i32 %0, 7
%4 = icmp slt i32 %0, 4147200
br i1 %4, label %5, label %46
5: ; preds = %2
%6 = srem i32 %3, 180
%7 = sdiv i32 %3, 180
%8 = shl nsw i32 %7, 1
%9 = icmp slt i32 %0, -45952
%10 = select i1 %9, i32 182, i32 -178
%11 = add nsw i32 %8, %10
%12 = sitofp i32 %11 to double
%13 = fsub double 1.800000e+02, %12
%14 = fmul double %13, 6.000000e+01
%15 = fdiv double %14, 5.000000e+00
%16 = fptosi double %15 to i32
%17 = sdiv i32 %16, 240
%18 = mul nsw i32 %17, -240
%19 = add i32 %18, %16
%20 = sdiv i32 %19, 24
%21 = add nsw i32 %17, 10
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [37 x i8], [37 x i8]* @__const.unpackgrid.c, i64 0, i64 %22
%24 = load i8, i8* %23
store i8 %24, i8* %1
%25 = sext i32 %20 to i64
%26 = getelementptr inbounds [37 x i8], [37 x i8]* @__const.unpackgrid.c, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %27, i8* %28
%29 = sitofp i32 %6 to double
%30 = fmul double %29, 6.000000e+01
%31 = fdiv double %30, 2.500000e+00
%32 = fptosi double %31 to i32
%33 = sdiv i32 %32, 240
%34 = mul nsw i32 %33, -240
%35 = add i32 %34, %32
%36 = sdiv i32 %35, 24
%37 = add nsw i32 %33, 10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [37 x i8], [37 x i8]* @__const.unpackgrid.c, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %40, i8* %41
%42 = sext i32 %36 to i64
%43 = getelementptr inbounds [37 x i8], [37 x i8]* @__const.unpackgrid.c, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %44, i8* %45
br label %48
46: ; preds = %2
%47 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %48
48: ; preds = %46, %5
ret void
}