void generics() {
  int a = 6;
  int *b = &a;
  double c = 9;
  double *d = &c;
  char *e = "yo\n";
  char **f = &e;
  char g = 'f';
  char *h = &g;
  generic_print(b, "d");
  generic_print(d, "lf");
  generic_print(h, "c");
  generic_print(f, "s");
  free(b);
  free(d);
  free(f);
  free(h);
}


x86 assembly (clang, -O0):
<generics>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x6,-0x4(%rbp)
lea    -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xeb5(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movb   $0x66,-0x31(%rbp)
lea    -0x31(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1040 <generic_print@plt>
mov    -0x20(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <generic_print@plt>
mov    -0x40(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1040 <generic_print@plt>
mov    -0x30(%rbp),%rdi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1040 <generic_print@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generics>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x6,0x4(%rsp)
movabs $0x4022000000000000,%rax
mov    %rax,0x10(%rsp)
lea    0xeb7(%rip),%rax
mov    %rax,0x8(%rsp)
movb   $0x66,0x3(%rsp)
lea    0xeaa(%rip),%rsi
lea    0x4(%rsp),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <generic_print@plt>
lea    0xe96(%rip),%rsi
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <generic_print@plt>
lea    0xe83(%rip),%rsi
lea    0x3(%rsp),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <generic_print@plt>
lea    0xe6f(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <generic_print@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"yo\0A\00"
@.str.1 = [2 x i8] c"d\00"
@.str.2 = [3 x i8] c"lf\00"
@.str.3 = [2 x i8] c"c\00"
@.str.4 = [2 x i8] c"s\00"
define void @generics() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca double
%4 = alloca double*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8
%8 = alloca i8*
store i32 6, i32* %1
store i32* %1, i32** %2
store double 9.000000e+00, double* %3
store double* %3, double** %4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %5
store i8** %5, i8*** %6
store i8 102, i8* %7
store i8* %7, i8** %8
%9 = load i32*, i32** %2
%10 = call i32 (i32*, i8*, ...) bitcast (i32 (...)* @generic_print to i32 (i32*, i8*, ...)*)(i32* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = load double*, double** %4
%12 = call i32 (double*, i8*, ...) bitcast (i32 (...)* @generic_print to i32 (double*, i8*, ...)*)(double* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = load i8*, i8** %8
%14 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @generic_print to i32 (i8*, i8*, ...)*)(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = load i8**, i8*** %6
%16 = call i32 (i8**, i8*, ...) bitcast (i32 (...)* @generic_print to i32 (i8**, i8*, ...)*)(i8** %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%17 = load i32*, i32** %2
%18 = bitcast i32* %17 to i8*
%19 = load double*, double** %4
%20 = bitcast double* %19 to i8*
%21 = load i8**, i8*** %6
%22 = bitcast i8** %21 to i8*
%23 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"yo\0A\00"
@.str.1 = [2 x i8] c"d\00"
@.str.2 = [3 x i8] c"lf\00"
@.str.3 = [2 x i8] c"c\00"
@.str.4 = [2 x i8] c"s\00"
define void @generics() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i8*
%4 = alloca i8
%5 = bitcast i32* %1 to i8*
store i32 6, i32* %1
%6 = bitcast double* %2 to i8*
store double 9.000000e+00, double* %2
%7 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %3
store i8 102, i8* %4
%8 = call i32 (i32*, i8*, ...) bitcast (i32 (...)* @generic_print to i32 (i32*, i8*, ...)*)(i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (double*, i8*, ...) bitcast (i32 (...)* @generic_print to i32 (double*, i8*, ...)*)(double* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @generic_print to i32 (i8*, i8*, ...)*)(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8**, i8*, ...) bitcast (i32 (...)* @generic_print to i32 (i8**, i8*, ...)*)(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}