#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 databuf {
  int dummy;
};

/* Variables and functions */
int binfile_read(char const *, struct databuf *);
int get_filetype(char const *);
int hexfile_read(char const *, struct databuf *);
int file_read(const char *filename, struct databuf *dbuf) {
  switch (get_filetype(filename)) {
  case 1:
    return binfile_read(filename, dbuf);
  case 2:
    return hexfile_read(filename, dbuf);
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<file_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <get_filetype@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0x1,%eax
je     116d <file_read+0x3d>
jmp    115c <file_read+0x2c>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1182 <file_read+0x52>
jmp    1197 <file_read+0x67>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <binfile_read@plt>
mov    %eax,-0x4(%rbp)
jmp    119e <file_read+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <hexfile_read@plt>
mov    %eax,-0x4(%rbp)
jmp    119e <file_read+0x6e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <get_filetype@plt>
cmp    $0x2,%eax
je     115b <file_read+0x2b>
cmp    $0x1,%eax
jne    116d <file_read+0x3d>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <binfile_read@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <hexfile_read@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.databuf = type { i32 }
define i32 @file_read(i8* %0, %struct.databuf* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.databuf*
store i8* %0, i8** %4
store %struct.databuf* %1, %struct.databuf** %5
%6 = load i8*, i8** %4
%7 = call i32 @get_filetype(i8* %6)
switch i32 %7, label %16 [
i32 1, label %8
i32 2, label %12
]
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = load %struct.databuf*, %struct.databuf** %5
%11 = call i32 @binfile_read(i8* %9, %struct.databuf* %10)
store i32 %11, i32* %3
br label %17
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load %struct.databuf*, %struct.databuf** %5
%15 = call i32 @hexfile_read(i8* %13, %struct.databuf* %14)
store i32 %15, i32* %3
br label %17
16: ; preds = %2
store i32 -1, i32* %3
br label %17
17: ; preds = %16, %12, %8
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
%struct.databuf = type { i32 }
define i32 @file_read(i8* %0, %struct.databuf* %1) {
%3 = tail call i32 @get_filetype(i8* %0)
switch i32 %3, label %8 [
i32 1, label %4
i32 2, label %6
]
4: ; preds = %2
%5 = tail call i32 @binfile_read(i8* %0, %struct.databuf* %1)
br label %8
6: ; preds = %2
%7 = tail call i32 @hexfile_read(i8* %0, %struct.databuf* %1)
br label %8
8: ; preds = %2, %6, %4
%9 = phi i32 [ %7, %6 ], [ %5, %4 ], [ -1, %2 ]
ret i32 %9
}