#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 */
struct res_model_list {
  int dummy;
};
struct ind_model_list {
  int dummy;
};
struct com_model_list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ abort();
int errno;
int /*<<< orphan*/ list_items_commodel(struct com_model_list *);
int /*<<< orphan*/ list_items_indmodel(struct ind_model_list *);
int /*<<< orphan*/ list_items_resmodel(struct res_model_list *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, char *);
struct com_model_list *read_commodel_list(int);
struct ind_model_list *read_indmodel_list(int);
struct res_model_list *read_resmodel_list(int);
void list_models(unsigned short type) {
  int fd;
  switch (type) {
  case 1:
    fd = open("resid.bin", O_RDONLY);
    if (fd < 0) {
      printf("Error %d opening %s!", errno, "resid.bin");
      abort();
    }
    struct res_model_list *list_a = read_resmodel_list(fd);
    list_items_resmodel(list_a);
    break;
  case 21:
    fd = open("comm.bin", O_RDONLY);
    struct com_model_list *list_b = read_commodel_list(fd);
    list_items_commodel(list_b);
    break;
  case 14:
    fd = open("indus.bin", O_RDONLY);
    struct ind_model_list *list_c = read_indmodel_list(fd);
    list_items_indmodel(list_c);
  };
}


x86 assembly (clang, -O0):
<list_models>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     11d6 <list_models+0x46>
jmp    11b4 <list_models+0x24>
mov    -0x24(%rbp),%eax
sub    $0xe,%eax
je     1267 <list_models+0xd7>
jmp    11c5 <list_models+0x35>
mov    -0x24(%rbp),%eax
sub    $0x15,%eax
je     1235 <list_models+0xa5>
jmp    1294 <list_models+0x104>
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    0xe1a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    121b <list_models+0x8b>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    0xe02(%rip),%rdi
lea    0xdf1(%rip),%rdx
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x8(%rbp),%edi
call   1080 <read_resmodel_list@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <list_items_resmodel@plt>
jmp    1294 <list_models+0x104>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xdda(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   10a0 <read_commodel_list@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <list_items_commodel@plt>
jmp    1294 <list_models+0x104>
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
lea    0xdb1(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <read_indmodel_list@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <list_items_indmodel@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_models>:
push   %rax
cmp    $0x15,%di
je     11cc <list_models+0x3c>
cmp    $0xe,%di
je     11f1 <list_models+0x61>
cmp    $0x1,%di
jne    1216 <list_models+0x86>
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
lea    0xe4d(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1218 <list_models+0x88>
mov    %eax,%edi
call   1080 <read_resmodel_list@plt>
mov    %rax,%rdi
pop    %rax
jmp    10b0 <list_items_resmodel@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    0xe43(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%edi
call   10a0 <read_commodel_list@plt>
mov    %rax,%rdi
pop    %rax
jmp    1070 <list_items_commodel@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
lea    0xe27(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%edi
call   1030 <read_indmodel_list@plt>
mov    %rax,%rdi
pop    %rax
jmp    1050 <list_items_indmodel@plt>
pop    %rax
ret
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
lea    0xde2(%rip),%rdi
lea    0xdd1(%rip),%rdx
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
%struct.res_model_list = type { i32 }
%struct.com_model_list = type { i32 }
%struct.ind_model_list = type { i32 }
@.str = [10 x i8] c"resid.bin\00"
@O_RDONLY = global i32 0
@.str.1 = [21 x i8] c"Error %d opening %s!\00"
@errno = global i32 0
@.str.2 = [9 x i8] c"comm.bin\00"
@.str.3 = [10 x i8] c"indus.bin\00"
define void @list_models(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i32
%4 = alloca %struct.res_model_list*
%5 = alloca %struct.com_model_list*
%6 = alloca %struct.ind_model_list*
store i16 %0, i16* %2
%7 = load i16, i16* %2
%8 = zext i16 %7 to i32
switch i32 %8, label %37 [
i32 1, label %9
i32 21, label %23
i32 14, label %30
]
9: ; preds = %1
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* @errno
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %9
%19 = load i32, i32* %3
%20 = call %struct.res_model_list* @read_resmodel_list(i32 %19)
store %struct.res_model_list* %20, %struct.res_model_list** %4
%21 = load %struct.res_model_list*, %struct.res_model_list** %4
%22 = call i32 @list_items_resmodel(%struct.res_model_list* %21)
br label %37
23: ; preds = %1
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %24)
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = call %struct.com_model_list* @read_commodel_list(i32 %26)
store %struct.com_model_list* %27, %struct.com_model_list** %5
%28 = load %struct.com_model_list*, %struct.com_model_list** %5
%29 = call i32 @list_items_commodel(%struct.com_model_list* %28)
br label %37
30: ; preds = %1
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %31)
store i32 %32, i32* %3
%33 = load i32, i32* %3
%34 = call %struct.ind_model_list* @read_indmodel_list(i32 %33)
store %struct.ind_model_list* %34, %struct.ind_model_list** %6
%35 = load %struct.ind_model_list*, %struct.ind_model_list** %6
%36 = call i32 @list_items_indmodel(%struct.ind_model_list* %35)
br label %37
37: ; preds = %30, %1, %23, %18
ret void
}

LLVM IR (-O2):
%struct.res_model_list = type { i32 }
%struct.com_model_list = type { i32 }
%struct.ind_model_list = type { i32 }
@.str = [10 x i8] c"resid.bin\00"
@O_RDONLY = global i32 0
@.str.1 = [21 x i8] c"Error %d opening %s!\00"
@errno = global i32 0
@.str.2 = [9 x i8] c"comm.bin\00"
@.str.3 = [10 x i8] c"indus.bin\00"
define void @list_models(i16 zeroext %0) {
switch i16 %0, label %23 [
i16 1, label %2
i16 21, label %13
i16 14, label %18
]
2: ; preds = %1
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %2
%11 = tail call %struct.res_model_list* @read_resmodel_list(i32 %4)
%12 = tail call i32 @list_items_resmodel(%struct.res_model_list* %11)
br label %23
13: ; preds = %1
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = tail call %struct.com_model_list* @read_commodel_list(i32 %15)
%17 = tail call i32 @list_items_commodel(%struct.com_model_list* %16)
br label %23
18: ; preds = %1
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = tail call %struct.ind_model_list* @read_indmodel_list(i32 %20)
%22 = tail call i32 @list_items_indmodel(%struct.ind_model_list* %21)
br label %23
23: ; preds = %18, %1, %13, %10
ret void
}