void generic_print(void *data, char *type) {
  if (strcmp(type, "d") == 0) {
    printf("%d", *(int *)data);
  } else if (strcmp(type, "u") == 0) {
    printf("%u", *(unsigned *)data);
  } else if (strcmp(type, "f") == 0) {
    printf("%f", *(float *)data);
  } else if (strcmp(type, "lf") == 0) {
    printf("%lf", *(double *)data);
  } else if (strcmp(type, "c") == 0) {
    printf("%c", *(char *)data);
  } else if (strcmp(type, "s") == 0) {
    printf("%s", *(char **)data);
  } else if (strcmp(type, "p") == 0) {
    printf("%p", data);
  }
}


x86 assembly (clang, -O0):
<generic_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec6(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1162 <generic_print+0x42>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12af <generic_print+0x18f>
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1194 <generic_print+0x74>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12aa <generic_print+0x18a>
mov    -0x10(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11cc <generic_print+0xac>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe46(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12a5 <generic_print+0x185>
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1200 <generic_print+0xe0>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xe15(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12a0 <generic_print+0x180>
mov    -0x10(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1233 <generic_print+0x113>
mov    -0x8(%rbp),%rax
movsbl (%rax),%esi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129b <generic_print+0x17b>
mov    -0x10(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1266 <generic_print+0x146>
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1296 <generic_print+0x176>
mov    -0x10(%rbp),%rdi
lea    0xda3(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1291 <generic_print+0x171>
mov    -0x8(%rbp),%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1296 <generic_print+0x176>
jmp    129b <generic_print+0x17b>
jmp    12a0 <generic_print+0x180>
jmp    12a5 <generic_print+0x185>
jmp    12aa <generic_print+0x18a>
jmp    12af <generic_print+0x18f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generic_print>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xec0(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c7 <generic_print+0x97>
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11d3 <generic_print+0xa3>
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11eb <generic_print+0xbb>
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11fd <generic_print+0xcd>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1217 <generic_print+0xe7>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1227 <generic_print+0xf7>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1233 <generic_print+0x103>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%r14),%esi
lea    0xe2f(%rip),%rdi
jmp    11dd <generic_print+0xad>
mov    (%r14),%esi
lea    0xe26(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
movss  (%r14),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe0b(%rip),%rdi
jmp    1209 <generic_print+0xd9>
movsd  (%r14),%xmm0
lea    0xe00(%rip),%rdi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
movsbl (%r14),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>
mov    (%r14),%rsi
lea    0xdde(%rip),%rdi
jmp    123d <generic_print+0x10d>
lea    0xdd8(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"u\00"
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [2 x i8] c"f\00"
@.str.5 = [3 x i8] c"%f\00"
@.str.6 = [3 x i8] c"lf\00"
@.str.7 = [4 x i8] c"%lf\00"
@.str.8 = [2 x i8] c"c\00"
@.str.9 = [3 x i8] c"%c\00"
@.str.10 = [2 x i8] c"s\00"
@.str.11 = [3 x i8] c"%s\00"
@.str.12 = [2 x i8] c"p\00"
@.str.13 = [3 x i8] c"%p\00"
define void @generic_print(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 i32 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %72
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %71
22: ; preds = %13
%23 = load i8*, i8** %4
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = bitcast i8* %27 to float*
%29 = load float, float* %28
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), double %30)
br label %70
32: ; preds = %22
%33 = load i8*, i8** %4
%34 = call i32 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i8*, i8** %3
%38 = bitcast i8* %37 to double*
%39 = load double, double* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), double %39)
br label %69
41: ; preds = %32
%42 = load i8*, i8** %4
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %41
%46 = load i8*, i8** %3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 %48)
br label %68
50: ; preds = %41
%51 = load i8*, i8** %4
%52 = call i32 @strcmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load i8*, i8** %3
%56 = bitcast i8* %55 to i8**
%57 = load i8*, i8** %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %57)
br label %67
59: ; preds = %50
%60 = load i8*, i8** %4
%61 = call i32 @strcmp(i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load i8*, i8** %3
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %63, %59
br label %67
67: ; preds = %66, %54
br label %68
68: ; preds = %67, %45
br label %69
69: ; preds = %68, %36
br label %70
70: ; preds = %69, %26
br label %71
71: ; preds = %70, %17
br label %72
72: ; preds = %71, %8
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"u\00"
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [2 x i8] c"f\00"
@.str.5 = [3 x i8] c"%f\00"
@.str.6 = [3 x i8] c"lf\00"
@.str.7 = [4 x i8] c"%lf\00"
@.str.8 = [2 x i8] c"c\00"
@.str.10 = [2 x i8] c"s\00"
@.str.11 = [3 x i8] c"%s\00"
@.str.12 = [2 x i8] c"p\00"
@.str.13 = [3 x i8] c"%p\00"
define void @generic_print(i8* %0, i8* nocapture %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = bitcast i8* %0 to i32*
%7 = load i32, i32* %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %50
9: ; preds = %2
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = bitcast i8* %0 to i32*
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %50
16: ; preds = %9
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = bitcast i8* %0 to float*
%21 = load float, float* %20
%22 = fpext float %21 to double
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), double %22)
br label %50
24: ; preds = %16
%25 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = bitcast i8* %0 to double*
%29 = load double, double* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), double %29)
br label %50
31: ; preds = %24
%32 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i8, i8* %0
%36 = sext i8 %35 to i32
%37 = tail call i32 @putchar(i32 %36)
br label %50
38: ; preds = %31
%39 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = bitcast i8* %0 to i8**
%43 = load i8*, i8** %42
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %43)
br label %50
45: ; preds = %38
%46 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %0)
br label %50
50: ; preds = %12, %27, %41, %48, %45, %34, %19, %5
ret void
}