#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*/ printk(char *, unsigned long, char *, int);
unsigned short from64to16(unsigned long x) {
  x = (x & 0xffffffff) + (x >> 32);
  x = (x & 0xffff) + (x >> 16);
  x = (x & 0xffff) + (x >> 16);
  x = (x & 0xffff) + (x >> 16);
  printk("i:%d, %s, %d\n", x,
         "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
         "2022-01-22/02-19-57/repos/gbtian/linux_mpip/refs/heads/master/arch/"
         "ia64/lib/checksum.c",
         29);
  return x;
}


x86 assembly (clang, -O0):
<from64to16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movabs $0xffffffff,%rax
and    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
shr    $0x20,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0xffff,%rax
mov    -0x8(%rbp),%rcx
shr    $0x10,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0xffff,%rax
mov    -0x8(%rbp),%rcx
shr    $0x10,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0xffff,%rax
mov    -0x8(%rbp),%rcx
shr    $0x10,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe71(%rip),%rdi
lea    0xe78(%rip),%rdx
mov    $0x1d,%ecx
call   1030 <printk@plt>
mov    -0x8(%rbp),%rax
movzwl %ax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<from64to16>:
push   %rbx
mov    %edi,%ebx
shr    $0x20,%rdi
add    %rdi,%rbx
movzwl %bx,%eax
shr    $0x10,%rbx
add    %rax,%rbx
movzwl %bx,%eax
shr    $0x10,%rbx
add    %rax,%rbx
movzwl %bx,%eax
shr    $0x10,%rbx
add    %rax,%rbx
lea    0xec1(%rip),%rdi
lea    0xec8(%rip),%rdx
mov    %rbx,%rsi
mov    $0x1d,%ecx
call   1030 <printk@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"i:%d, %s, %d\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gbtian/linux_mpip/refs/heads/master/arch/ia64/lib/checksum.c\00"
define zeroext i16 @from64to16(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = and i64 %3, 4294967295
%5 = load i64, i64* %2
%6 = lshr i64 %5, 32
%7 = add i64 %4, %6
store i64 %7, i64* %2
%8 = load i64, i64* %2
%9 = and i64 %8, 65535
%10 = load i64, i64* %2
%11 = lshr i64 %10, 16
%12 = add i64 %9, %11
store i64 %12, i64* %2
%13 = load i64, i64* %2
%14 = and i64 %13, 65535
%15 = load i64, i64* %2
%16 = lshr i64 %15, 16
%17 = add i64 %14, %16
store i64 %17, i64* %2
%18 = load i64, i64* %2
%19 = and i64 %18, 65535
%20 = load i64, i64* %2
%21 = lshr i64 %20, 16
%22 = add i64 %19, %21
store i64 %22, i64* %2
%23 = load i64, i64* %2
%24 = call i32 @printk(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 %23, i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 29)
%25 = load i64, i64* %2
%26 = trunc i64 %25 to i16
ret i16 %26
}

LLVM IR (-O2):
@.str = [14 x i8] c"i:%d, %s, %d\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gbtian/linux_mpip/refs/heads/master/arch/ia64/lib/checksum.c\00"
define zeroext i16 @from64to16(i64 %0) {
%2 = and i64 %0, 4294967295
%3 = lshr i64 %0, 32
%4 = add nuw nsw i64 %2, %3
%5 = and i64 %4, 65535
%6 = lshr i64 %4, 16
%7 = add nuw nsw i64 %5, %6
%8 = and i64 %7, 65535
%9 = lshr i64 %7, 16
%10 = add nuw nsw i64 %8, %9
%11 = and i64 %10, 65535
%12 = lshr i64 %10, 16
%13 = add nuw nsw i64 %11, %12
%14 = tail call i32 @printk(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 %13, i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 29)
%15 = trunc i64 %13 to i16
ret i16 %15
}