#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_type_string(int type) {
  static char buf[32];
  if (type == 0x1)
    return "Electric meter";
  if (type == 0x2)
    return "Gas meter";
  if (type == 0x3)
    return "Water meter";
  sprintf(buf, "(unknown meter type %d)", type);
  return buf;
}


x86 assembly (clang, -O0):
<get_meter_type_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1135 <get_meter_type_string+0x25>
lea    0xed4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118a <get_meter_type_string+0x7a>
cmpl   $0x2,-0xc(%rbp)
jne    114f <get_meter_type_string+0x3f>
lea    0xec9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118a <get_meter_type_string+0x7a>
cmpl   $0x3,-0xc(%rbp)
jne    1169 <get_meter_type_string+0x59>
lea    0xeb9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118a <get_meter_type_string+0x7a>
mov    -0xc(%rbp),%edx
lea    0x2ecd(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2eba(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_meter_type_string>:
push   %rbx
mov    %edi,%edx
lea    -0x1(%rdx),%eax
cmp    $0x3,%eax
jae    112d <get_meter_type_string+0x1d>
cltq
lea    0xf1c(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1143 <get_meter_type_string+0x33>
lea    0x2f0c(%rip),%rbx
lea    0xeea(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@get_meter_type_string.buf = internal global [32 x i8] zeroinitializer
@.str = [15 x i8] c"Electric meter\00"
@.str.1 = [10 x i8] c"Gas meter\00"
@.str.2 = [12 x i8] c"Water meter\00"
@.str.3 = [24 x i8] c"(unknown meter type %d)\00"
define i8* @get_meter_type_string(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %2
br label %18
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %11
10: ; preds = %7
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %18
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %15
14: ; preds = %11
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %18
15: ; preds = %11
%16 = load i32, i32* %3
%17 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_meter_type_string.buf, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %16)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_meter_type_string.buf, i64 0, i64 0), i8** %2
br label %18
18: ; preds = %15, %14, %10, %6
%19 = load i8*, i8** %2
ret i8* %19
}

LLVM IR (-O2):
@get_meter_type_string.buf = internal global [32 x i8] zeroinitializer
@.str = [15 x i8] c"Electric meter\00"
@.str.1 = [10 x i8] c"Gas meter\00"
@.str.2 = [12 x i8] c"Water meter\00"
@.str.3 = [24 x i8] c"(unknown meter type %d)\00"
@reltable.get_meter_type_string = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.get_meter_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.get_meter_type_string to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.get_meter_type_string to i64)) to i32)]
define i8* @get_meter_type_string(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 3
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @get_meter_type_string.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %10
6: ; preds = %1
%7 = sext i32 %2 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.get_meter_type_string to i8*), i64 %8)
br label %10
10: ; preds = %6, %4
%11 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @get_meter_type_string.buf, i64 0, i64 0), %4 ], [ %9, %6 ]
ret i8* %11
}