#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 grid_db {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int determine_file_format(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ get_epa_info(char *, struct grid_db *);
int /*<<< orphan*/ get_gr3d_info(char *, struct grid_db *);
int /*<<< orphan*/ get_grads_info(char *, struct grid_db *);
int /*<<< orphan*/ get_grid_info(char *, struct grid_db *);
int /*<<< orphan*/ get_uwvis_info(char *, struct grid_db *);
int /*<<< orphan*/ get_v5d_info(char *, struct grid_db *);
int /*<<< orphan*/ printf(char *, char *);
void get_file_info(char *name, struct grid_db *db) {
  FILE *f;
  int kind;
  f = fopen(name, "r");
  if (!f) {
    printf("Warning:  couldn't open %s\n", name);
    return;
  }
  fclose(f);
  kind = determine_file_format(name);
  switch (kind) {
  case 1:
    get_gr3d_info(name, db);
    break;
  case 6:
    get_grid_info(name, db);
    break;
  case 2:
    get_epa_info(name, db);
    break;
  case 3:
    get_v5d_info(name, db);
    break;
  case 4:
    get_grads_info(name, db);
    break;
  case 5:
    get_uwvis_info(name, db);
    break;
  case 0:
  default:
    printf("Warning:  %s is of unknown type\n", name);
    break;
  }
}


x86 assembly (clang, -O0):
<get_file_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <get_file_info+0x44>
mov    -0x8(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1060 <printf@plt>
jmp    129f <get_file_info+0xff>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1090 <determine_file_format@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x6,%rax
ja     128f <get_file_info+0xef>
mov    -0x28(%rbp),%rax
lea    0xdeb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <get_gr3d_info@plt>
jmp    129f <get_file_info+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <get_grid_info@plt>
jmp    129f <get_file_info+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <get_epa_info@plt>
jmp    129f <get_file_info+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <get_v5d_info@plt>
jmp    129f <get_file_info+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <get_grads_info@plt>
jmp    129f <get_file_info+0xff>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10c0 <get_uwvis_info@plt>
jmp    129f <get_file_info+0xff>
jmp    128f <get_file_info+0xef>
mov    -0x8(%rbp),%rsi
lea    0xda0(%rip),%rdi
call   1060 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_info>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe67(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11f9 <get_file_info+0x59>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1090 <determine_file_format@plt>
add    $0xffffffff,%eax
cmp    $0x5,%eax
ja     1269 <get_file_info+0xc9>
lea    0xe22(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <get_gr3d_info@plt>
lea    0xe1a(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10b0 <get_epa_info@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <get_v5d_info@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <get_grads_info@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10c0 <get_uwvis_info@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <get_grid_info@plt>
lea    0xdc6(%rip),%rdi
jmp    1200 <get_file_info+0x60>

LLVM IR (-O0):
%struct.grid_db = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Warning: couldn't open %s\0A\00"
@.str.2 = [33 x i8] c"Warning: %s is of unknown type\0A\00"
define void @get_file_info(i8* %0, %struct.grid_db* %1) {
%3 = alloca i8*
%4 = alloca %struct.grid_db*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store %struct.grid_db* %1, %struct.grid_db** %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %48
14: ; preds = %2
%15 = load i32*, i32** %5
%16 = call i32 @fclose(i32* %15)
%17 = load i8*, i8** %3
%18 = call i32 @determine_file_format(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
switch i32 %19, label %45 [
i32 1, label %20
i32 6, label %24
i32 2, label %28
i32 3, label %32
i32 4, label %36
i32 5, label %40
i32 0, label %44
]
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = load %struct.grid_db*, %struct.grid_db** %4
%23 = call i32 @get_gr3d_info(i8* %21, %struct.grid_db* %22)
br label %48
24: ; preds = %14
%25 = load i8*, i8** %3
%26 = load %struct.grid_db*, %struct.grid_db** %4
%27 = call i32 @get_grid_info(i8* %25, %struct.grid_db* %26)
br label %48
28: ; preds = %14
%29 = load i8*, i8** %3
%30 = load %struct.grid_db*, %struct.grid_db** %4
%31 = call i32 @get_epa_info(i8* %29, %struct.grid_db* %30)
br label %48
32: ; preds = %14
%33 = load i8*, i8** %3
%34 = load %struct.grid_db*, %struct.grid_db** %4
%35 = call i32 @get_v5d_info(i8* %33, %struct.grid_db* %34)
br label %48
36: ; preds = %14
%37 = load i8*, i8** %3
%38 = load %struct.grid_db*, %struct.grid_db** %4
%39 = call i32 @get_grads_info(i8* %37, %struct.grid_db* %38)
br label %48
40: ; preds = %14
%41 = load i8*, i8** %3
%42 = load %struct.grid_db*, %struct.grid_db** %4
%43 = call i32 @get_uwvis_info(i8* %41, %struct.grid_db* %42)
br label %48
44: ; preds = %14
br label %45
45: ; preds = %14, %44
%46 = load i8*, i8** %3
%47 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %11, %45, %40, %36, %32, %28, %24, %20
ret void
}

LLVM IR (-O2):
%struct.grid_db = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Warning: couldn't open %s\0A\00"
@.str.2 = [33 x i8] c"Warning: %s is of unknown type\0A\00"
define void @get_file_info(i8* %0, %struct.grid_db* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %24
7: ; preds = %2
%8 = tail call i32 @fclose(i32* %3)
%9 = tail call i32 @determine_file_format(i8* %0)
switch i32 %9, label %22 [
i32 1, label %10
i32 6, label %12
i32 2, label %14
i32 3, label %16
i32 4, label %18
i32 5, label %20
]
10: ; preds = %7
%11 = tail call i32 @get_gr3d_info(i8* %0, %struct.grid_db* %1)
br label %24
12: ; preds = %7
%13 = tail call i32 @get_grid_info(i8* %0, %struct.grid_db* %1)
br label %24
14: ; preds = %7
%15 = tail call i32 @get_epa_info(i8* %0, %struct.grid_db* %1)
br label %24
16: ; preds = %7
%17 = tail call i32 @get_v5d_info(i8* %0, %struct.grid_db* %1)
br label %24
18: ; preds = %7
%19 = tail call i32 @get_grads_info(i8* %0, %struct.grid_db* %1)
br label %24
20: ; preds = %7
%21 = tail call i32 @get_uwvis_info(i8* %0, %struct.grid_db* %1)
br label %24
22: ; preds = %7
%23 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %10, %12, %14, %16, %18, %20, %22, %5
ret void
}