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

/* Variables and functions */
char *basename_get_filename(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ get_line(char *, int /*<<< orphan*/ *);
scalar_t__ piece(char *, char, char *, int /*<<< orphan*/);
scalar_t__ strcasecmp(char *, char *);
char *get_station(char *full_filename) {
  char *filename;
  static char station[256];
  char input_buffer[1024];
  char piece_buffer[1024];
  FILE *input_file;
  filename = basename_get_filename(full_filename);
  piece(station, '_', filename, 0);
  if (!(input_file = fopen(full_filename, "r")))
    return (char *)0;
  if (!get_line(input_buffer, input_file)) {
    fclose(input_file);
    return station;
  }
  if (piece(piece_buffer, ',', input_buffer, 0)) {
    if (strcasecmp(piece_buffer, "Station Name") != 0) {
      fclose(input_file);
      return station;
    }
    if (!get_line(input_buffer, input_file)) {
      fclose(input_file);
      return station;
    }
    if (!piece(station, ',', input_buffer, 0)) {
      fclose(input_file);
      return station;
    }
  }
  fclose(input_file);
  return station;
}


x86 assembly (clang, -O0):
<get_station>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <basename_get_filename@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
lea    0x2ed9(%rip),%rdi
mov    $0x5f,%esi
xor    %ecx,%ecx
call   1070 <piece@plt>
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x828(%rbp)
cmp    $0x0,%rax
jne    11c1 <get_station+0x61>
movq   $0x0,-0x8(%rbp)
jmp    12ea <get_station+0x18a>
lea    -0x420(%rbp),%rdi
mov    -0x828(%rbp),%rsi
call   1040 <get_line@plt>
cmp    $0x0,%eax
jne    11f9 <get_station+0x99>
mov    -0x828(%rbp),%rdi
call   1050 <fclose@plt>
lea    0x2e70(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ea <get_station+0x18a>
lea    -0x820(%rbp),%rdi
lea    -0x420(%rbp),%rdx
mov    $0x2c,%esi
xor    %ecx,%ecx
call   1070 <piece@plt>
cmp    $0x0,%rax
je     12d3 <get_station+0x173>
lea    -0x820(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     1256 <get_station+0xf6>
mov    -0x828(%rbp),%rdi
call   1050 <fclose@plt>
lea    0x2e13(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ea <get_station+0x18a>
lea    -0x420(%rbp),%rdi
mov    -0x828(%rbp),%rsi
call   1040 <get_line@plt>
cmp    $0x0,%eax
jne    128e <get_station+0x12e>
mov    -0x828(%rbp),%rdi
call   1050 <fclose@plt>
lea    0x2ddb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ea <get_station+0x18a>
lea    -0x420(%rbp),%rdx
lea    0x2dc4(%rip),%rdi
mov    $0x2c,%esi
xor    %ecx,%ecx
call   1070 <piece@plt>
cmp    $0x0,%rax
jne    12ce <get_station+0x16e>
mov    -0x828(%rbp),%rdi
call   1050 <fclose@plt>
lea    0x2d9b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12ea <get_station+0x18a>
jmp    12d3 <get_station+0x173>
mov    -0x828(%rbp),%rdi
call   1050 <fclose@plt>
lea    0x2d7a(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_station>:
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%rbx
call   1080 <basename_get_filename@plt>
lea    0x2ee7(%rip),%r14
mov    %r14,%rdi
mov    $0x5f,%esi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1070 <piece@plt>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1215 <get_station+0xb5>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    %rax,%rsi
call   1040 <get_line@plt>
test   %eax,%eax
je     120b <get_station+0xab>
lea    0x400(%rsp),%rdi
mov    %rsp,%rdx
mov    $0x2c,%esi
xor    %ecx,%ecx
call   1070 <piece@plt>
test   %rax,%rax
je     120b <get_station+0xab>
lea    0xe2e(%rip),%rsi
lea    0x400(%rsp),%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    120b <get_station+0xab>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1040 <get_line@plt>
test   %eax,%eax
je     120b <get_station+0xab>
lea    0x2e64(%rip),%rdi
mov    %rsp,%rdx
mov    $0x2c,%esi
xor    %ecx,%ecx
call   1070 <piece@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1218 <get_station+0xb8>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@get_station.station = internal global [256 x i8] zeroinitializer
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"Station Name\00"
define i8* @get_station(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i8* @basename_get_filename(i8* %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = call i64 @piece(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), i8 signext 95, i8* %10, i32 0)
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %16, label %15
15: ; preds = %1
store i8* null, i8** %2
br label %55
16: ; preds = %1
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = load i32*, i32** %7
%19 = call i32 @get_line(i8* %17, i32* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i32*, i32** %7
%23 = call i32 @fclose(i32* %22)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), i8** %2
br label %55
24: ; preds = %16
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%27 = call i64 @piece(i8* %25, i8 signext 44, i8* %26, i32 0)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %52
29: ; preds = %24
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = call i64 @strcasecmp(i8* %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), i8** %2
br label %55
36: ; preds = %29
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%38 = load i32*, i32** %7
%39 = call i32 @get_line(i8* %37, i32* %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %36
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), i8** %2
br label %55
44: ; preds = %36
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%46 = call i64 @piece(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), i8 signext 44, i8* %45, i32 0)
%47 = icmp ne i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %44
%49 = load i32*, i32** %7
%50 = call i32 @fclose(i32* %49)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), i8** %2
br label %55
51: ; preds = %44
br label %52
52: ; preds = %51, %24
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), i8** %2
br label %55
55: ; preds = %52, %48, %41, %33, %21, %15
%56 = load i8*, i8** %2
ret i8* %56
}

LLVM IR (-O2):
@get_station.station = internal global [256 x i8] zeroinitializer
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"Station Name\00"
define i8* @get_station(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = tail call i8* @basename_get_filename(i8* %0)
%7 = tail call i64 @piece(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), i8 signext 95, i8* %6, i32 0)
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %26, label %10
10: ; preds = %1
%11 = call i32 @get_line(i8* %4, i32* %8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %10
%14 = call i64 @piece(i8* %5, i8 signext 44, i8* %4, i32 0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = call i32 @get_line(i8* %4, i32* %8)
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i64 @piece(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), i8 signext 44, i8* %4, i32 0)
br label %24
24: ; preds = %22, %13, %19, %16, %10
%25 = call i32 @fclose(i32* %8)
br label %26
26: ; preds = %24, %1
%27 = phi i8* [ null, %1 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @get_station.station, i64 0, i64 0), %24 ]
ret i8* %27
}