#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 */
const char *getFmt(const char *a) {
  const char *fmt = "%x";
  if (*a == '0') {
    switch (*++a) {
    case 'x':
      fmt = "%x";
      ++a;
      break;
    case 'd':
      fmt = "%d";
      ++a;
      break;
    default:
      fmt = "%o";
      break;
    }
  }
  return fmt;
}


x86 assembly (clang, -O0):
<getFmt>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
lea    0xef1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11a0 <getFmt+0xa0>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x64,%eax
je     1174 <getFmt+0x74>
jmp    1147 <getFmt+0x47>
mov    -0x14(%rbp),%eax
sub    $0x78,%eax
jne    1190 <getFmt+0x90>
jmp    1158 <getFmt+0x58>
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119b <getFmt+0x9b>
lea    0xe88(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119b <getFmt+0x9b>
lea    0xe6f(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11a0 <getFmt+0xa0>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFmt>:
cmpb   $0x30,(%rdi)
jne    112a <getFmt+0x2a>
mov    0x1(%rdi),%al
cmp    $0x64,%al
lea    0xef2(%rip),%rcx
lea    0xeee(%rip),%rdx
cmove  %rcx,%rdx
cmp    $0x78,%al
lea    0xedb(%rip),%rax
cmovne %rdx,%rax
ret
lea    0xecf(%rip),%rax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%o\00"
define i8* @getFmt(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = icmp eq i32 %6, 48
br i1 %7, label %8, label %21
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %19 [
i32 120, label %13
i32 100, label %16
]
13: ; preds = %8
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %2
br label %20
16: ; preds = %8
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %3
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %2
br label %20
19: ; preds = %8
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %20
20: ; preds = %19, %16, %13
br label %21
21: ; preds = %20, %1
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%o\00"
define i8* @getFmt(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 48
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 100
%8 = select i1 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%9 = icmp eq i8 %6, 120
%10 = select i1 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8
br label %11
11: ; preds = %4, %1
%12 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %1 ], [ %10, %4 ]
ret i8* %12
}