char *chkIntSize(sz)
int sz;
{
  if (sizeof(char) == sz) {
    return "char";
  } else if (sizeof(int) == sz) {
    return "int";
  } else if (sizeof(short) == sz) {
    return "short";
  } else if (sizeof(long int) == sz) {
    return "long int";
  } else if (sizeof(long long int) == sz) {
    return "long long int";
  } else {
    return "unknown";
  }
}


x86 assembly (clang, -O0):
<chkIntSize>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rcx
mov    $0x1,%eax
cmp    %rcx,%rax
jne    1129 <chkIntSize+0x29>
lea    0xee0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <chkIntSize+0xbc>
movslq -0xc(%rbp),%rcx
mov    $0x4,%eax
cmp    %rcx,%rax
jne    114b <chkIntSize+0x4b>
lea    0xed3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <chkIntSize+0xbc>
movslq -0xc(%rbp),%rcx
mov    $0x2,%eax
cmp    %rcx,%rax
jne    116d <chkIntSize+0x6d>
lea    0xea1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <chkIntSize+0xbc>
movslq -0xc(%rbp),%rcx
mov    $0x8,%eax
cmp    %rcx,%rax
jne    118f <chkIntSize+0x8f>
lea    0xe8a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <chkIntSize+0xbc>
movslq -0xc(%rbp),%rcx
mov    $0x8,%eax
cmp    %rcx,%rax
jne    11b1 <chkIntSize+0xb1>
lea    0xe63(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <chkIntSize+0xbc>
lea    0xe61(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<chkIntSize>:
add    $0xffffffff,%edi
cmp    $0x7,%edi
ja     111a <chkIntSize+0x1a>
movslq %edi,%rax
lea    0xf0a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xef3(%rip),%rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"char\00"
@.str.1 = [4 x i8] c"int\00"
@.str.2 = [6 x i8] c"short\00"
@.str.3 = [9 x i8] c"long int\00"
@.str.4 = [14 x i8] c"long long int\00"
@.str.5 = [8 x i8] c"unknown\00"
define i8* @chkIntSize(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = sext i32 %4 to i64
%6 = icmp eq i64 1, %5
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
br label %29
8: ; preds = %1
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = icmp eq i64 4, %10
br i1 %11, label %12, label %13
12: ; preds = %8
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %29
13: ; preds = %8
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = icmp eq i64 2, %15
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %29
18: ; preds = %13
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = icmp eq i64 8, %20
br i1 %21, label %22, label %23
22: ; preds = %18
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %29
23: ; preds = %18
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = icmp eq i64 8, %25
br i1 %26, label %27, label %28
27: ; preds = %23
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %29
28: ; preds = %23
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %29
29: ; preds = %28, %27, %22, %17, %12, %7
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@.str = [5 x i8] c"char\00"
@.str.1 = [4 x i8] c"int\00"
@.str.2 = [6 x i8] c"short\00"
@.str.3 = [9 x i8] c"long int\00"
@.str.5 = [8 x i8] c"unknown\00"
@reltable.chkIntSize = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.chkIntSize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.chkIntSize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.chkIntSize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.chkIntSize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.chkIntSize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.chkIntSize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.chkIntSize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.chkIntSize to i64)) to i32)]
define i8* @chkIntSize(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 8
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.chkIntSize to i8*), i64 %6)
br label %8
8: ; preds = %1, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %1 ]
ret i8* %9
}