#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 */
typedef int uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
uint8_t PiToCallsign(uint16_t picode, char *callsign) {
  if ((picode > 4095) && (picode < 39247)) {
    if (picode > 21671) {
      callsign[0] = 'W';
      picode -= 21672;
    } else {
      callsign[0] = 'K';
      picode -= 4096;
    }
    callsign[1] = (picode / 676) + 65;
    picode %= 676;
    callsign[2] = (picode / 26) + 65;
    picode %= 26;
    callsign[3] = picode + 65;
    callsign[4] = '\0';
    return 0;
  } else {
    memset(callsign, 0, 4);
    return 1;
  }
}


x86 assembly (clang, -O0):
<PiToCallsign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0xfff,-0x8(%rbp)
jle    11dc <PiToCallsign+0xcc>
cmpl   $0x994f,-0x8(%rbp)
jge    11dc <PiToCallsign+0xcc>
cmpl   $0x54a7,-0x8(%rbp)
jle    115d <PiToCallsign+0x4d>
mov    -0x10(%rbp),%rax
movb   $0x57,(%rax)
mov    -0x8(%rbp),%eax
sub    $0x54a8,%eax
mov    %eax,-0x8(%rbp)
jmp    116f <PiToCallsign+0x5f>
mov    -0x10(%rbp),%rax
movb   $0x4b,(%rax)
mov    -0x8(%rbp),%eax
sub    $0x1000,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2a4,%ecx
cltd
idiv   %ecx
add    $0x41,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x8(%rbp),%eax
mov    $0x2a4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x41,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x4(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f3 <PiToCallsign+0xe3>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PiToCallsign>:
push   %rax
lea    -0x1000(%rdi),%eax
cmp    $0x894e,%eax
ja     1133 <PiToCallsign+0x23>
cmp    $0x54a8,%edi
jb     1149 <PiToCallsign+0x39>
movb   $0x57,(%rsi)
add    $0xffffab58,%edi
mov    %edi,%eax
jmp    114c <PiToCallsign+0x3c>
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    $0x1,%eax
pop    %rcx
ret
movb   $0x4b,(%rsi)
movzwl %ax,%ecx
imul   $0xc1e5,%ecx,%ecx
shr    $0x19,%ecx
lea    0x41(%rcx),%edx
mov    %dl,0x1(%rsi)
imul   $0x2a4,%ecx,%ecx
sub    %ecx,%eax
movzwl %ax,%ecx
imul   $0x4ec5,%ecx,%ecx
shr    $0x13,%ecx
lea    0x41(%rcx),%edx
mov    %dl,0x2(%rsi)
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,0x3(%rsi)
movb   $0x0,0x4(%rsi)
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @PiToCallsign(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 4095
br i1 %7, label %8, label %48
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 39247
br i1 %10, label %11, label %48
11: ; preds = %8
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 21671
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 87, i8* %16
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 21672
store i32 %18, i32* %4
br label %24
19: ; preds = %11
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 75, i8* %21
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 4096
store i32 %23, i32* %4
br label %24
24: ; preds = %19, %14
%25 = load i32, i32* %4
%26 = sdiv i32 %25, 676
%27 = add nsw i32 %26, 65
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8 %28, i8* %30
%31 = load i32, i32* %4
%32 = srem i32 %31, 676
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = sdiv i32 %33, 26
%35 = add nsw i32 %34, 65
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 2
store i8 %36, i8* %38
%39 = load i32, i32* %4
%40 = srem i32 %39, 26
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 65
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i64 3
store i8 %43, i8* %45
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i64 4
store i8 0, i8* %47
store i32 0, i32* %3
br label %51
48: ; preds = %8, %2
%49 = load i8*, i8** %5
%50 = call i32 @memset(i8* %49, i32 0, i32 4)
store i32 1, i32* %3
br label %51
51: ; preds = %48, %24
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
define i32 @PiToCallsign(i32 %0, i8* %1) {
%3 = add i32 %0, -4096
%4 = icmp ult i32 %3, 35151
br i1 %4, label %5, label %27
5: ; preds = %2
%6 = icmp ugt i32 %0, 21671
br i1 %6, label %7, label %9
7: ; preds = %5
store i8 87, i8* %1
%8 = add nsw i32 %0, -21672
br label %10
9: ; preds = %5
store i8 75, i8* %1
br label %10
10: ; preds = %9, %7
%11 = phi i32 [ %8, %7 ], [ %3, %9 ]
%12 = trunc i32 %11 to i16
%13 = udiv i16 %12, 676
%14 = trunc i16 %13 to i8
%15 = add nuw nsw i8 %14, 65
%16 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %15, i8* %16
%17 = urem i16 %12, 676
%18 = udiv i16 %17, 26
%19 = trunc i16 %18 to i8
%20 = add nuw nsw i8 %19, 65
%21 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %20, i8* %21
%22 = urem i16 %17, 26
%23 = trunc i16 %22 to i8
%24 = add nuw nsw i8 %23, 65
%25 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %24, i8* %25
%26 = getelementptr inbounds i8, i8* %1, i64 4
store i8 0, i8* %26
br label %29
27: ; preds = %2
%28 = tail call i32 @memset(i8* %1, i32 0, i32 4)
br label %29
29: ; preds = %27, %10
%30 = phi i32 [ 0, %10 ], [ 1, %27 ]
ret i32 %30
}