#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
char *matrix_type(int type) {
  char *res = (char *)malloc(16 * sizeof(char));
  switch (type) {
  case 1:
    sprintf(res, "%s", "dense general");
    break;
  case 2:
    sprintf(res, "%s", "dense diagonal");
    break;
  case 10:
    sprintf(res, "%s", "sparse general");
    break;
  case 20:
    sprintf(res, "%s", "sparse diagonal");
    break;
  default:
    fprintf(stderr, "Error: matrix_type - unknown type '%d'\n", type);
    exit(1);
  }
  return res;
}


x86 assembly (clang, -O0):
<matrix_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x13,%eax
ja     11f2 <matrix_type+0xb2>
mov    -0x18(%rbp),%rax
lea    0xe87(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xec3(%rip),%rsi
lea    0xebf(%rip),%rdx
call   1050 <sprintf@plt>
jmp    1214 <matrix_type+0xd4>
mov    -0x10(%rbp),%rdi
lea    0xea7(%rip),%rsi
lea    0xeb1(%rip),%rdx
call   1050 <sprintf@plt>
jmp    1214 <matrix_type+0xd4>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
lea    0xea4(%rip),%rdx
call   1050 <sprintf@plt>
jmp    1214 <matrix_type+0xd4>
mov    -0x10(%rbp),%rdi
lea    0xe6f(%rip),%rsi
lea    0xe97(%rip),%rdx
call   1050 <sprintf@plt>
jmp    1214 <matrix_type+0xd4>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe8a(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_type>:
push   %rbx
mov    %edi,%ebx
mov    $0x10,%edi
call   1040 <malloc@plt>
lea    -0x1(%rbx),%ecx
cmp    $0x13,%ecx
ja     11b2 <matrix_type+0x82>
lea    0xeb4(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
movabs $0x6c6172656e6567,%rcx
mov    %rcx,0x6(%rax)
movabs $0x65672065736e6564,%rcx
20 67 65
jmp    11ad <matrix_type+0x7d>
movabs $0x6c6172656e6567,%rcx
mov    %rcx,0x7(%rax)
movabs $0x6720657372617073,%rcx
65 20 67
jmp    11ad <matrix_type+0x7d>
movups 0xeec(%rip),%xmm0
movups %xmm0,(%rax)
pop    %rbx
ret
movabs $0x6c616e6f676169,%rcx
mov    %rcx,0x7(%rax)
movabs $0x69642065736e6564,%rcx
20 64 69
mov    %rcx,(%rax)
pop    %rbx
ret
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xeca(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [14 x i8] c"dense general\00"
@.str.2 = [15 x i8] c"dense diagonal\00"
@.str.3 = [15 x i8] c"sparse general\00"
@.str.4 = [16 x i8] c"sparse diagonal\00"
@stderr = global i32 0
@.str.5 = [40 x i8] c"Error: matrix_type - unknown type '%d'\0A\00"
define i8* @matrix_type(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i64 @malloc(i32 16)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = load i32, i32* %2
switch i32 %6, label %19 [
i32 1, label %7
i32 2, label %10
i32 10, label %13
i32 20, label %16
]
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %24
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %24
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %24
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %24
19: ; preds = %1
%20 = load i32, i32* @stderr
%21 = load i32, i32* %2
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16, %13, %10, %7
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"dense general\00"
@.str.2 = [15 x i8] c"dense diagonal\00"
@.str.3 = [15 x i8] c"sparse general\00"
@.str.4 = [16 x i8] c"sparse diagonal\00"
@stderr = global i32 0
@.str.5 = [40 x i8] c"Error: matrix_type - unknown type '%d'\0A\00"
define i8* @matrix_type(i32 %0) {
%2 = tail call i64 @malloc(i32 16)
%3 = inttoptr i64 %2 to i8*
switch i32 %0, label %8 [
i32 1, label %4
i32 2, label %5
i32 10, label %6
i32 20, label %7
]
4: ; preds = %1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(14) %3, i8* align 1 dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 14, i1 false)
br label %12
5: ; preds = %1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(15) %3, i8* align 1 dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 15, i1 false)
br label %12
6: ; preds = %1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(15) %3, i8* align 1 dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 15, i1 false)
br label %12
7: ; preds = %1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(16) %3, i8* align 1 dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i64 16, i1 false)
br label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %7, %6, %5, %4
ret i8* %3
}