#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*/ snprintf(char *, size_t, char *, ...);
char *sizer(char *buffer, size_t capacity, size_t vsize, const void *value) {
  switch (vsize) {
  case 2:
    snprintf(buffer, capacity, "%hu", *((const short unsigned *)value));
    break;
  case 4:
    if (sizeof(long) == 4) {
      snprintf(buffer, capacity, "%lu", *((const long unsigned *)value));
    } else {
      snprintf(buffer, capacity, "%u", *((const unsigned *)value));
    }
    break;
  case 8:
    if (sizeof(long) == 4) {
      snprintf(buffer, capacity, "%llu", *((const long long unsigned *)value));
    } else {
      snprintf(buffer, capacity, "%lu", *((const long unsigned *)value));
    }
    break;
  default:
    snprintf(buffer, capacity, "unknown");
    break;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<sizer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
sub    $0x2,%rax
je     1165 <sizer+0x55>
jmp    113f <sizer+0x2f>
mov    -0x28(%rbp),%rax
sub    $0x4,%rax
je     1187 <sizer+0x77>
jmp    1152 <sizer+0x42>
mov    -0x28(%rbp),%rax
sub    $0x8,%rax
je     11a8 <sizer+0x98>
jmp    11ca <sizer+0xba>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
movzwl (%rax),%ecx
lea    0xe85(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11e0 <sizer+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xe68(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11e0 <sizer+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xe49(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11e0 <sizer+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe32(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sizer>:
push   %rbx
mov    %rdi,%rbx
cmp    $0x8,%rdx
je     1132 <sizer+0x22>
cmp    $0x4,%rdx
je     1148 <sizer+0x38>
cmp    $0x2,%rdx
jne    115d <sizer+0x4d>
movzwl (%rcx),%ecx
lea    0xed0(%rip),%rdx
jmp    1151 <sizer+0x41>
mov    (%rcx),%rcx
lea    0xecb(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    116e <sizer+0x5e>
mov    (%rcx),%ecx
lea    0xeb3(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    116e <sizer+0x5e>
lea    0xea7(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%hu\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [4 x i8] c"%lu\00"
@.str.3 = [8 x i8] c"unknown\00"
define i8* @sizer(i8* %0, i64 %1, i64 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%9 = load i64, i64* %7
switch i64 %9, label %32 [
i64 2, label %10
i64 4, label %18
i64 8, label %25
]
10: ; preds = %4
%11 = load i8*, i8** %5
%12 = load i64, i64* %6
%13 = load i8*, i8** %8
%14 = bitcast i8* %13 to i16*
%15 = load i16, i16* %14
%16 = zext i16 %15 to i32
%17 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %11, i64 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %36
18: ; preds = %4
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = load i8*, i8** %8
%22 = bitcast i8* %21 to i32*
%23 = load i32, i32* %22
%24 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %19, i64 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %36
25: ; preds = %4
%26 = load i8*, i8** %5
%27 = load i64, i64* %6
%28 = load i8*, i8** %8
%29 = bitcast i8* %28 to i64*
%30 = load i64, i64* %29
%31 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %26, i64 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %30)
br label %36
32: ; preds = %4
%33 = load i8*, i8** %5
%34 = load i64, i64* %6
%35 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %33, i64 %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %32, %25, %18, %10
%37 = load i8*, i8** %5
ret i8* %37
}

LLVM IR (-O2):
@.str = [4 x i8] c"%hu\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [4 x i8] c"%lu\00"
@.str.3 = [8 x i8] c"unknown\00"
define i8* @sizer(i8* returned writeonly %0, i64 %1, i64 %2, i8* nocapture %3) {
switch i64 %2, label %18 [
i64 2, label %5
i64 4, label %10
i64 8, label %14
]
5: ; preds = %4
%6 = bitcast i8* %3 to i16*
%7 = load i16, i16* %6
%8 = zext i16 %7 to i32
%9 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %20
10: ; preds = %4
%11 = bitcast i8* %3 to i32*
%12 = load i32, i32* %11
%13 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %20
14: ; preds = %4
%15 = bitcast i8* %3 to i64*
%16 = load i64, i64* %15
%17 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %16)
br label %20
18: ; preds = %4
%19 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %14, %10, %5
ret i8* %0
}