#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 */
char returnchar(unsigned short);
void derad50(unsigned short x, char *s) {
  s[2] = returnchar(x % 40);
  x /= 40;
  s[1] = returnchar(x % 40);
  x /= 40;
  s[0] = returnchar(x % 40);
}


x86 assembly (clang, -O0):
<derad50>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movzwl -0x2(%rbp),%eax
mov    $0x28,%ecx
cltd
idiv   %ecx
mov    %dx,%ax
movzwl %ax,%edi
call   1030 <returnchar@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
movzwl -0x2(%rbp),%eax
mov    $0x28,%ecx
cltd
idiv   %ecx
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
mov    $0x28,%ecx
cltd
idiv   %ecx
mov    %dx,%ax
movzwl %ax,%edi
call   1030 <returnchar@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
movzwl -0x2(%rbp),%eax
mov    $0x28,%ecx
cltd
idiv   %ecx
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
mov    $0x28,%ecx
cltd
idiv   %ecx
mov    %dx,%ax
movzwl %ax,%edi
call   1030 <returnchar@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<derad50>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
imul   $0xcccd,%edi,%ebx
shr    $0x15,%ebx
lea    0x0(,%rbx,8),%eax
lea    (%rax,%rax,4),%eax
mov    %edi,%ecx
sub    %eax,%ecx
movzwl %cx,%edi
call   1030 <returnchar@plt>
mov    %al,0x2(%r14)
imul   $0xcccd,%ebx,%eax
shr    $0x12,%eax
and    $0xfffffff8,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
movzwl %bx,%edi
call   1030 <returnchar@plt>
mov    %al,0x1(%r14)
shr    $0x6,%ebp
imul   $0xa3e,%ebp,%eax
shr    $0x10,%eax
imul   $0xcd,%eax,%ecx
shr    $0xa,%ecx
and    $0xfffffff8,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%al
movzbl %al,%edi
call   1030 <returnchar@plt>
mov    %al,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @derad50(i16 zeroext %0, i8* %1) {
%3 = alloca i16
%4 = alloca i8*
store i16 %0, i16* %3
store i8* %1, i8** %4
%5 = load i16, i16* %3
%6 = zext i16 %5 to i32
%7 = srem i32 %6, 40
%8 = trunc i32 %7 to i16
%9 = call signext i8 @returnchar(i16 zeroext %8)
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 2
store i8 %9, i8* %11
%12 = load i16, i16* %3
%13 = zext i16 %12 to i32
%14 = sdiv i32 %13, 40
%15 = trunc i32 %14 to i16
store i16 %15, i16* %3
%16 = load i16, i16* %3
%17 = zext i16 %16 to i32
%18 = srem i32 %17, 40
%19 = trunc i32 %18 to i16
%20 = call signext i8 @returnchar(i16 zeroext %19)
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 %20, i8* %22
%23 = load i16, i16* %3
%24 = zext i16 %23 to i32
%25 = sdiv i32 %24, 40
%26 = trunc i32 %25 to i16
store i16 %26, i16* %3
%27 = load i16, i16* %3
%28 = zext i16 %27 to i32
%29 = srem i32 %28, 40
%30 = trunc i32 %29 to i16
%31 = call signext i8 @returnchar(i16 zeroext %30)
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 0
store i8 %31, i8* %33
ret void
}

LLVM IR (-O2):
define void @derad50(i16 zeroext %0, i8* nocapture writeonly %1) {
%3 = urem i16 %0, 40
%4 = tail call signext i8 @returnchar(i16 zeroext %3)
%5 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %4, i8* %5
%6 = udiv i16 %0, 40
%7 = urem i16 %6, 40
%8 = tail call signext i8 @returnchar(i16 zeroext %7)
%9 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %8, i8* %9
%10 = udiv i16 %0, 1600
%11 = trunc i16 %10 to i8
%12 = urem i8 %11, 40
%13 = zext i8 %12 to i16
%14 = tail call signext i8 @returnchar(i16 zeroext %13)
store i8 %14, i8* %1
ret void
}