#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 */
void cmpp_pack_set_integer(void *pack, size_t offset, unsigned long long val,
                           size_t size) {
  if (!pack) {
    return;
  }
  unsigned char *ptr = (unsigned char *)pack + offset;
  switch (size) {
  case 1:
    *((unsigned char *)ptr) = (unsigned char)val;
    break;
  case 2:
    *((unsigned short *)ptr) = (unsigned short)val;
    break;
  case 4:
    *((unsigned int *)ptr) = (unsigned int)val;
    break;
  case 8:
    *((unsigned long long *)ptr) = (unsigned long int)val;
    break;
  default:
    break;
  }
  return;
}


x86 assembly (clang, -O0):
<cmpp_pack_set_integer>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1124 <cmpp_pack_set_integer+0x24>
jmp    11ac <cmpp_pack_set_integer+0xac>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
sub    $0x7,%rax
ja     11a2 <cmpp_pack_set_integer+0xa2>
mov    -0x30(%rbp),%rax
lea    0xeac(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
jmp    11a7 <cmpp_pack_set_integer+0xa7>
mov    -0x18(%rbp),%rax
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %cx,(%rax)
jmp    11a7 <cmpp_pack_set_integer+0xa7>
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    11a7 <cmpp_pack_set_integer+0xa7>
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    11a7 <cmpp_pack_set_integer+0xa7>
jmp    11a7 <cmpp_pack_set_integer+0xa7>
jmp    11ac <cmpp_pack_set_integer+0xac>
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmpp_pack_set_integer>:
test   %rdi,%rdi
je     1130 <cmpp_pack_set_integer+0x30>
add    $0xffffffffffffffff,%rcx
cmp    $0x7,%rcx
ja     1130 <cmpp_pack_set_integer+0x30>
lea    0xeea(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %dl,(%rdi,%rsi,1)
ret
mov    %dx,(%rdi,%rsi,1)
ret
mov    %edx,(%rdi,%rsi,1)
ret
mov    %rdx,(%rdi,%rsi,1)
ret

LLVM IR (-O0):
define void @cmpp_pack_set_integer(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %4
br label %38
13: ; preds = %4
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = getelementptr inbounds i8, i8* %14, i64 %15
store i8* %16, i8** %9
%17 = load i64, i64* %8
switch i64 %17, label %36 [
i64 1, label %18
i64 2, label %22
i64 4, label %27
i64 8, label %32
]
18: ; preds = %13
%19 = load i64, i64* %7
%20 = trunc i64 %19 to i8
%21 = load i8*, i8** %9
store i8 %20, i8* %21
br label %37
22: ; preds = %13
%23 = load i64, i64* %7
%24 = trunc i64 %23 to i16
%25 = load i8*, i8** %9
%26 = bitcast i8* %25 to i16*
store i16 %24, i16* %26
br label %37
27: ; preds = %13
%28 = load i64, i64* %7
%29 = trunc i64 %28 to i32
%30 = load i8*, i8** %9
%31 = bitcast i8* %30 to i32*
store i32 %29, i32* %31
br label %37
32: ; preds = %13
%33 = load i64, i64* %7
%34 = load i8*, i8** %9
%35 = bitcast i8* %34 to i64*
store i64 %33, i64* %35
br label %37
36: ; preds = %13
br label %37
37: ; preds = %36, %32, %27, %22, %18
br label %38
38: ; preds = %37, %12
ret void
}

LLVM IR (-O2):
define void @cmpp_pack_set_integer(i8* writeonly %0, i64 %1, i64 %2, i64 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %18, label %6
6: ; preds = %4
%7 = getelementptr inbounds i8, i8* %0, i64 %1
switch i64 %3, label %18 [
i64 1, label %8
i64 2, label %10
i64 4, label %13
i64 8, label %16
]
8: ; preds = %6
%9 = trunc i64 %2 to i8
store i8 %9, i8* %7
br label %18
10: ; preds = %6
%11 = trunc i64 %2 to i16
%12 = bitcast i8* %7 to i16*
store i16 %11, i16* %12
br label %18
13: ; preds = %6
%14 = trunc i64 %2 to i32
%15 = bitcast i8* %7 to i32*
store i32 %14, i32* %15
br label %18
16: ; preds = %6
%17 = bitcast i8* %7 to i64*
store i64 %2, i64* %17
br label %18
18: ; preds = %8, %10, %13, %16, %6, %4
ret void
}