#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*/ printAsCharString(char const *);
int /*<<< orphan*/ printAsHexString(char const *);
scalar_t__ strncmp(char const *, char *, int);
void printAs(const char *str, const char *format) {
  if (strncmp(format, "char", 4) == 0) {
    printAsCharString(str);
  } else if (strncmp(format, "hex", 3) == 0) {
    printAsHexString(str);
  }
}


x86 assembly (clang, -O0):
<printAs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    116d <printAs+0x3d>
mov    -0x8(%rbp),%rdi
call   1040 <printAsCharString@plt>
jmp    119a <printAs+0x6a>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1195 <printAs+0x65>
mov    -0x8(%rbp),%rdi
call   1050 <printAsHexString@plt>
jmp    119a <printAs+0x6a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printAs>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1174 <printAs+0x44>
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1183 <printAs+0x53>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printAsCharString@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printAsHexString@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"char\00"
@.str.1 = [4 x i8] c"hex\00"
define void @printAs(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32 @printAsCharString(i8* %9)
br label %19
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = call i32 @printAsHexString(i8* %16)
br label %18
18: ; preds = %15, %11
br label %19
19: ; preds = %18, %8
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"char\00"
@.str.1 = [4 x i8] c"hex\00"
define void @printAs(i8* %0, i8* %1) {
%3 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printAsCharString(i8* %0)
br label %12
7: ; preds = %2
%8 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @printAsHexString(i8* %0)
br label %12
12: ; preds = %7, %10, %5
ret void
}