const char *minimum_size_type(int lwr, int upr, int *pnByte) {
  const char *zType = "int32";
  int nByte = 4;
  if (lwr >= 0) {
    if (upr <= 255) {
      zType = "uint8";
      nByte = 1;
    } else if (upr < 65535) {
      zType = "uint16";
      nByte = 2;
    } else {
      zType = "uint32";
      nByte = 4;
    }
  } else if (lwr >= -127 && upr <= 127) {
    zType = "int8";
    nByte = 1;
  } else if (lwr >= -32767 && upr < 32767) {
    zType = "int16";
    nByte = 2;
  }
  if (pnByte)
    *pnByte = nByte;
  return zType;
}


x86 assembly (clang, -O0):
<minimum_size_type>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xef9(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x4,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     118e <minimum_size_type+0x8e>
cmpl   $0xff,-0x8(%rbp)
jg     114e <minimum_size_type+0x4e>
lea    0xec2(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    1189 <minimum_size_type+0x89>
cmpl   $0xffff,-0x8(%rbp)
jge    1172 <minimum_size_type+0x72>
lea    0xea4(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
jmp    1184 <minimum_size_type+0x84>
lea    0xe94(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x4,-0x1c(%rbp)
jmp    1189 <minimum_size_type+0x89>
jmp    11ef <minimum_size_type+0xef>
cmpl   $0xffffff81,-0x4(%rbp)
jl     11b9 <minimum_size_type+0xb9>
cmpl   $0x7f,-0x8(%rbp)
jg     11b9 <minimum_size_type+0xb9>
lea    0xe58(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    11ea <minimum_size_type+0xea>
cmpl   $0xffff8001,-0x4(%rbp)
jl     11e5 <minimum_size_type+0xe5>
cmpl   $0x7fff,-0x8(%rbp)
jge    11e5 <minimum_size_type+0xe5>
lea    0xe2d(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
jmp    11ea <minimum_size_type+0xea>
jmp    11ef <minimum_size_type+0xef>
cmpq   $0x0,-0x10(%rbp)
je     1203 <minimum_size_type+0x103>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<minimum_size_type>:
test   %edi,%edi
js     111a <minimum_size_type+0x1a>
cmp    $0x100,%esi
jge    1135 <minimum_size_type+0x35>
mov    $0x1,%ecx
lea    0xee8(%rip),%rax
jmp    1185 <minimum_size_type+0x85>
cmp    $0xffffff81,%edi
jb     1154 <minimum_size_type+0x54>
cmp    $0x80,%esi
jge    1154 <minimum_size_type+0x54>
mov    $0x1,%ecx
lea    0xece(%rip),%rax
jmp    1185 <minimum_size_type+0x85>
xor    %ecx,%ecx
cmp    $0xffff,%esi
setae  %cl
lea    0xebf(%rip),%rsi
lea    0xebf(%rip),%rax
cmovb  %rsi,%rax
jmp    1180 <minimum_size_type+0x80>
cmp    $0xffff8001,%edi
setae  %al
cmp    $0x7fff,%esi
setl   %cl
and    %al,%cl
lea    0xe98(%rip),%rsi
lea    0xe98(%rip),%rax
cmovne %rsi,%rax
xor    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%ecx
add    $0x2,%ecx
test   %rdx,%rdx
je     118c <minimum_size_type+0x8c>
mov    %ecx,(%rdx)
ret

LLVM IR (-O0):
@.str = [6 x i8] c"int32\00"
@.str.1 = [6 x i8] c"uint8\00"
@.str.2 = [7 x i8] c"uint16\00"
@.str.3 = [7 x i8] c"uint32\00"
@.str.4 = [5 x i8] c"int8\00"
@.str.5 = [6 x i8] c"int16\00"
define i8* @minimum_size_type(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 4, i32* %8
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 255
br i1 %13, label %14, label %15
14: ; preds = %11
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i32 1, i32* %8
br label %21
15: ; preds = %11
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 65535
br i1 %17, label %18, label %19
18: ; preds = %15
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %7
store i32 2, i32* %8
br label %20
19: ; preds = %15
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %7
store i32 4, i32* %8
br label %20
20: ; preds = %19, %18
br label %21
21: ; preds = %20, %14
br label %38
22: ; preds = %3
%23 = load i32, i32* %4
%24 = icmp sge i32 %23, -127
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %5
%27 = icmp sle i32 %26, 127
br i1 %27, label %28, label %29
28: ; preds = %25
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %7
store i32 1, i32* %8
br label %37
29: ; preds = %25, %22
%30 = load i32, i32* %4
%31 = icmp sge i32 %30, -32767
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 32767
br i1 %34, label %35, label %36
35: ; preds = %32
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8** %7
store i32 2, i32* %8
br label %36
36: ; preds = %35, %32, %29
br label %37
37: ; preds = %36, %28
br label %38
38: ; preds = %37, %21
%39 = load i32*, i32** %6
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %8
%43 = load i32*, i32** %6
store i32 %42, i32* %43
br label %44
44: ; preds = %41, %38
%45 = load i8*, i8** %7
ret i8* %45
}

LLVM IR (-O2):
@.str = [6 x i8] c"int32\00"
@.str.1 = [6 x i8] c"uint8\00"
@.str.2 = [7 x i8] c"uint16\00"
@.str.3 = [7 x i8] c"uint32\00"
@.str.4 = [5 x i8] c"int8\00"
@.str.5 = [6 x i8] c"int16\00"
define i8* @minimum_size_type(i32 %0, i32 %1, i32* writeonly %2) {
%4 = icmp sgt i32 %0, -1
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = icmp slt i32 %1, 256
br i1 %6, label %21, label %7
7: ; preds = %5
%8 = icmp ult i32 %1, 65535
%9 = select i1 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%10 = select i1 %8, i32 2, i32 4
br label %21
11: ; preds = %3
%12 = icmp ugt i32 %0, -128
%13 = icmp slt i32 %1, 128
%14 = and i1 %12, %13
br i1 %14, label %21, label %15
15: ; preds = %11
%16 = icmp ugt i32 %0, -32768
%17 = icmp slt i32 %1, 32767
%18 = and i1 %16, %17
%19 = select i1 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0)
%20 = select i1 %18, i32 2, i32 4
br label %21
21: ; preds = %15, %11, %7, %5
%22 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %5 ], [ %9, %7 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %11 ], [ %19, %15 ]
%23 = phi i32 [ 1, %5 ], [ %10, %7 ], [ 1, %11 ], [ %20, %15 ]
%24 = icmp eq i32* %2, null
br i1 %24, label %26, label %25
25: ; preds = %21
store i32 %23, i32* %2
br label %26
26: ; preds = %25, %21
ret i8* %22
}