#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
void closefile(FILE *handle, char *filename) {
  char b[1000];
  if ((strcmp(&filename[strlen(filename) - 2], ".Z") == 0) ||
      (strcmp(&filename[strlen(filename) - 3], ".gz") == 0)) {
    while (fgets(b, 999, handle) != NULL)
      ;
    pclose(handle);
  } else {
    fclose(handle);
  }
}


x86 assembly (clang, -O0):
<closefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x408(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x408(%rbp),%rdi
sub    $0x2,%eax
cltq
add    %rax,%rdi
lea    0xe73(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11d5 <closefile+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,-0x410(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x410(%rbp),%rdi
sub    $0x3,%eax
cltq
add    %rax,%rdi
lea    0xe3d(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    120c <closefile+0xbc>
jmp    11da <closefile+0x8a>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3e7,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11fe <closefile+0xae>
jmp    11da <closefile+0x8a>
mov    -0x8(%rbp),%rdi
call   1050 <pclose@plt>
jmp    1215 <closefile+0xc5>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<closefile>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rdi
add    $0xfffffffffffffffe,%rdi
lea    0xe87(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11b8 <closefile+0x68>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xe67(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11b8 <closefile+0x68>
mov    %rbx,%rdi
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x3e7,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11c0 <closefile+0x70>
mov    %rbx,%rdi
call   1050 <pclose@plt>
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c".Z\00"
@.str.1 = [4 x i8] c".gz\00"
define void @closefile(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [1000 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %8, 2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %14, %2
br label %24
24: ; preds = %29, %23
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%26 = load i32*, i32** %3
%27 = call i32* @fgets(i8* %25, i32 999, i32* %26)
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24
br label %24
30: ; preds = %24
%31 = load i32*, i32** %3
%32 = call i32 @pclose(i32* %31)
br label %36
33: ; preds = %14
%34 = load i32*, i32** %3
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %33, %30
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c".Z\00"
@.str.1 = [4 x i8] c".gz\00"
define void @closefile(i32* nocapture %0, i8* %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, -2
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = tail call i32 @strlen(i8* %1)
%13 = add nsw i32 %12, -3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %11, %2
br label %19
19: ; preds = %18, %19
%20 = call i32* @fgets(i8* %4, i32 999, i32* %0)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %19
22: ; preds = %19
%23 = call i32 @pclose(i32* %0)
br label %26
24: ; preds = %11
%25 = tail call i32 @fclose(i32* %0)
br label %26
26: ; preds = %24, %22
ret void
}