#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*/ sprintf(char *, char *, int);
char *get_meter_scale_string(int type, int scale) {
  static char buf[32];
  if (type == 0x1) {
    if (scale == 0)
      return "kWh";
    if (scale == 1)
      return "kVAh";
    if (scale == 2)
      return "W";
    if (scale == 3)
      return "Pulse count";
  }
  if (type == 0x2) {
    if (scale == 0)
      return "Cubic metersh";
    if (scale == 1)
      return "Cublic feet";
    if (scale == 3)
      return "Pulse count";
  }
  if (type == 0x3) {
    if (scale == 0)
      return "Cubic metersh";
    if (scale == 1)
      return "Cublic feet";
    if (scale == 2)
      return "US gallons";
    if (scale == 3)
      return "Pulse count";
  }
  sprintf(buf, "(unknown meter scale %d)", scale);
  return buf;
}


x86 assembly (clang, -O0):
<get_meter_scale_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1195 <get_meter_scale_string+0x85>
cmpl   $0x0,-0x10(%rbp)
jne    1142 <get_meter_scale_string+0x32>
lea    0xec7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
cmpl   $0x1,-0x10(%rbp)
jne    115c <get_meter_scale_string+0x4c>
lea    0xeb1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
cmpl   $0x2,-0x10(%rbp)
jne    1176 <get_meter_scale_string+0x66>
lea    0xe9c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
cmpl   $0x3,-0x10(%rbp)
jne    1190 <get_meter_scale_string+0x80>
lea    0xe84(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
jmp    1195 <get_meter_scale_string+0x85>
cmpl   $0x2,-0xc(%rbp)
jne    11f2 <get_meter_scale_string+0xe2>
cmpl   $0x0,-0x10(%rbp)
jne    11b9 <get_meter_scale_string+0xa9>
lea    0xe67(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
cmpl   $0x1,-0x10(%rbp)
jne    11d3 <get_meter_scale_string+0xc3>
lea    0xe5b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
cmpl   $0x3,-0x10(%rbp)
jne    11ed <get_meter_scale_string+0xdd>
lea    0xe27(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
jmp    11f2 <get_meter_scale_string+0xe2>
cmpl   $0x3,-0xc(%rbp)
jne    1269 <get_meter_scale_string+0x159>
cmpl   $0x0,-0x10(%rbp)
jne    1216 <get_meter_scale_string+0x106>
lea    0xe0a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
cmpl   $0x1,-0x10(%rbp)
jne    1230 <get_meter_scale_string+0x120>
lea    0xdfe(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
cmpl   $0x2,-0x10(%rbp)
jne    124a <get_meter_scale_string+0x13a>
lea    0xdf0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
cmpl   $0x3,-0x10(%rbp)
jne    1264 <get_meter_scale_string+0x154>
lea    0xdb0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <get_meter_scale_string+0x17a>
jmp    1269 <get_meter_scale_string+0x159>
mov    -0x10(%rbp),%edx
lea    0x2dcd(%rip),%rdi
lea    0xdc2(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2dba(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_meter_scale_string>:
push   %rbx
mov    %esi,%edx
cmp    $0x3,%edi
je     114a <get_meter_scale_string+0x3a>
cmp    $0x2,%edi
je     1133 <get_meter_scale_string+0x23>
cmp    $0x1,%edi
jne    1162 <get_meter_scale_string+0x52>
cmp    $0x4,%edx
jae    1162 <get_meter_scale_string+0x52>
movslq %edx,%rax
lea    0xf27(%rip),%rcx
jmp    1159 <get_meter_scale_string+0x49>
test   %edx,%edx
je     117d <get_meter_scale_string+0x6d>
cmp    $0x3,%edx
je     1186 <get_meter_scale_string+0x76>
cmp    $0x1,%edx
jne    1162 <get_meter_scale_string+0x52>
lea    0xedd(%rip),%rbx
jmp    1178 <get_meter_scale_string+0x68>
cmp    $0x4,%edx
jae    1162 <get_meter_scale_string+0x52>
movslq %edx,%rax
lea    0xf0f(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1178 <get_meter_scale_string+0x68>
lea    0x2ed7(%rip),%rbx
lea    0xecc(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret
lea    0xe93(%rip),%rbx
jmp    1178 <get_meter_scale_string+0x68>
lea    0xe7e(%rip),%rbx
jmp    1178 <get_meter_scale_string+0x68>

LLVM IR (-O0):
@get_meter_scale_string.buf = internal global [32 x i8] zeroinitializer
@.str = [4 x i8] c"kWh\00"
@.str.1 = [5 x i8] c"kVAh\00"
@.str.2 = [2 x i8] c"W\00"
@.str.3 = [12 x i8] c"Pulse count\00"
@.str.4 = [14 x i8] c"Cubic metersh\00"
@.str.5 = [12 x i8] c"Cublic feet\00"
@.str.6 = [11 x i8] c"US gallons\00"
@.str.7 = [25 x i8] c"(unknown meter scale %d)\00"
define i8* @get_meter_scale_string(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %25
8: ; preds = %2
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %3
br label %64
12: ; preds = %8
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %64
16: ; preds = %12
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %16
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %64
20: ; preds = %16
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 3
br i1 %22, label %23, label %24
23: ; preds = %20
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %64
24: ; preds = %20
br label %25
25: ; preds = %24, %2
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %41
28: ; preds = %25
%29 = load i32, i32* %5
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %28
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %64
32: ; preds = %28
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %32
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %64
36: ; preds = %32
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 3
br i1 %38, label %39, label %40
39: ; preds = %36
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %64
40: ; preds = %36
br label %41
41: ; preds = %40, %25
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 3
br i1 %43, label %44, label %61
44: ; preds = %41
%45 = load i32, i32* %5
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %64
48: ; preds = %44
%49 = load i32, i32* %5
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %52
51: ; preds = %48
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %64
52: ; preds = %48
%53 = load i32, i32* %5
%54 = icmp eq i32 %53, 2
br i1 %54, label %55, label %56
55: ; preds = %52
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %64
56: ; preds = %52
%57 = load i32, i32* %5
%58 = icmp eq i32 %57, 3
br i1 %58, label %59, label %60
59: ; preds = %56
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %64
60: ; preds = %56
br label %61
61: ; preds = %60, %41
%62 = load i32, i32* %5
%63 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_meter_scale_string.buf, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %62)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_meter_scale_string.buf, i64 0, i64 0), i8** %3
br label %64
64: ; preds = %61, %59, %55, %51, %47, %39, %35, %31, %23, %19, %15, %11
%65 = load i8*, i8** %3
ret i8* %65
}

LLVM IR (-O2):
@get_meter_scale_string.buf = internal global [32 x i8] zeroinitializer
@.str = [4 x i8] c"kWh\00"
@.str.1 = [5 x i8] c"kVAh\00"
@.str.2 = [2 x i8] c"W\00"
@.str.3 = [12 x i8] c"Pulse count\00"
@.str.4 = [14 x i8] c"Cubic metersh\00"
@.str.5 = [12 x i8] c"Cublic feet\00"
@.str.6 = [11 x i8] c"US gallons\00"
@.str.7 = [25 x i8] c"(unknown meter scale %d)\00"
@reltable.get_meter_scale_string = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.get_meter_scale_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_meter_scale_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_meter_scale_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_meter_scale_string to i64)) to i32)]
@reltable.get_meter_scale_string.9 = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_meter_scale_string.9 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.5 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_meter_scale_string.9 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.6 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_meter_scale_string.9 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.get_meter_scale_string.9 to i64)) to i32)]
define i8* @get_meter_scale_string(i32 %0, i32 %1) {
switch i32 %0, label %10 [
i32 1, label %3
i32 2, label %5
i32 3, label %8
]
3: ; preds = %2
%4 = icmp ult i32 %1, 4
br i1 %4, label %12, label %10
5: ; preds = %2
switch i32 %1, label %10 [
i32 0, label %20
i32 1, label %6
i32 3, label %7
]
6: ; preds = %5
br label %20
7: ; preds = %5
br label %20
8: ; preds = %2
%9 = icmp ult i32 %1, 4
br i1 %9, label %16, label %10
10: ; preds = %8, %3, %5, %2
%11 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @get_meter_scale_string.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %1)
br label %20
12: ; preds = %3
%13 = sext i32 %1 to i64
%14 = shl i64 %13, 2
%15 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.get_meter_scale_string to i8*), i64 %14)
br label %20
16: ; preds = %8
%17 = sext i32 %1 to i64
%18 = shl i64 %17, 2
%19 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.get_meter_scale_string.9 to i8*), i64 %18)
br label %20
20: ; preds = %16, %12, %5, %10, %7, %6
%21 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), %6 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), %7 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @get_meter_scale_string.buf, i64 0, i64 0), %10 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %5 ], [ %15, %12 ], [ %19, %16 ]
ret i8* %21
}