#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*/ error_check(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
void print_array(char c, void *data, int count) {
  for (int i = 0; i != count; ++i) {
    if (i != 0)
      printf(", ");
    switch (c) {
    case 'd':
      printf("%d", ((int *)data)[i]);
      break;
    case 'f':
      printf("%f", ((float *)data)[i]);
      break;
    case 'x':
      printf("0x%x", ((unsigned *)data)[i]);
      break;
    default:
      error_check(1, "unsupported print argument");
    }
  }
  puts("");
}


x86 assembly (clang, -O0):
<print_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     122b <print_array+0xfb>
cmpl   $0x0,-0x18(%rbp)
je     1170 <print_array+0x40>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x1(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x64,%eax
je     11a7 <print_array+0x77>
jmp    1185 <print_array+0x55>
mov    -0x1c(%rbp),%eax
sub    $0x66,%eax
je     11c5 <print_array+0x95>
jmp    1196 <print_array+0x66>
mov    -0x1c(%rbp),%eax
sub    $0x78,%eax
je     11e9 <print_array+0xb9>
jmp    1207 <print_array+0xd7>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1218 <print_array+0xe8>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe29(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1218 <print_array+0xe8>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1218 <print_array+0xe8>
mov    $0x1,%edi
lea    0xdfb(%rip),%rsi
call   1050 <error_check@plt>
jmp    121d <print_array+0xed>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114c <print_array+0x1c>
lea    0xdd0(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     11af <print_array+0x7f>
mov    %edx,%ebp
mov    %rsi,%rbx
movsbl %dil,%r15d
cmp    $0x64,%r15d
je     1165 <print_array+0x35>
cmp    $0x66,%r15d
je     117c <print_array+0x4c>
cmp    $0x78,%r15d
jne    1199 <print_array+0x69>
mov    (%rbx),%esi
lea    0xea6(%rip),%rdi
jmp    116e <print_array+0x3e>
mov    (%rbx),%esi
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%ebp
je     11af <print_array+0x7f>
jmp    11c7 <print_array+0x97>
movss  (%rbx),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe7b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmp    $0x1,%ebp
je     11af <print_array+0x7f>
jmp    11c7 <print_array+0x97>
lea    0xe6e(%rip),%rsi
mov    $0x1,%edi
call   1050 <error_check@plt>
cmp    $0x1,%ebp
jne    11c7 <print_array+0x97>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
mov    %ebp,%r12d
mov    $0x1,%r13d
lea    0xe29(%rip),%r14
lea    0xe30(%rip),%rbp
jmp    1201 <print_array+0xd1>
movss  (%rbx,%r13,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe15(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%r13
cmp    %r13,%r12
je     11af <print_array+0x7f>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x78,%r15d
je     1230 <print_array+0x100>
cmp    $0x66,%r15d
je     11e0 <print_array+0xb0>
cmp    $0x64,%r15d
jne    1250 <print_array+0x120>
mov    (%rbx,%r13,4),%esi
lea    0xddb(%rip),%rdi
jmp    123b <print_array+0x10b>
nopw   0x0(%rax,%rax,1)
mov    (%rbx,%r13,4),%esi
lea    0xdce(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f8 <print_array+0xc8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1,%edi
mov    %rbp,%rsi
call   1050 <error_check@plt>
jmp    11f8 <print_array+0xc8>

LLVM IR (-O0):
@.str = [3 x i8] c", \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [5 x i8] c"0x%x\00"
@.str.4 = [27 x i8] c"unsupported print argument\00"
@.str.5 = [1 x i8] zeroinitializer
define void @print_array(i8 signext %0, i8* %1, i32 %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8 %0, i8* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %48, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %51
12: ; preds = %8
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
switch i32 %19, label %45 [
i32 100, label %20
i32 102, label %28
i32 120, label %37
]
20: ; preds = %17
%21 = load i8*, i8** %5
%22 = bitcast i8* %21 to i32*
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %47
28: ; preds = %17
%29 = load i8*, i8** %5
%30 = bitcast i8* %29 to float*
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds float, float* %30, i64 %32
%34 = load float, float* %33
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double %35)
br label %47
37: ; preds = %17
%38 = load i8*, i8** %5
%39 = bitcast i8* %38 to i32*
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %43)
br label %47
45: ; preds = %17
%46 = call i32 @error_check(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %37, %28, %20
br label %48
48: ; preds = %47
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %8
51: ; preds = %8
%52 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
ret void
}

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