#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*/ *fopen(char *, char *);
void foo() {
  FILE *x = fopen("xyz", "r");
  FILE *y = fopen("abc", "r");
  if (x)
    fclose(x);
  if (y)
    fclose(y);
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
lea    0xece(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    0xec0(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     116a <foo+0x4a>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x10(%rbp)
je     117e <foo+0x5e>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rdi
lea    0xed2(%rip),%r14
mov    %r14,%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
lea    0xec2(%rip),%rdi
mov    %r14,%rsi
call   1040 <fopen@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     115c <foo+0x3c>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r14,%r14
je     1170 <foo+0x50>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"xyz\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"abc\00"
define void @foo() {
%1 = alloca i32*
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32*, i32** %1
%9 = call i32 @fclose(i32* %8)
br label %10
10: ; preds = %7, %0
%11 = load i32*, i32** %2
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32*, i32** %2
%15 = call i32 @fclose(i32* %14)
br label %16
16: ; preds = %13, %10
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"xyz\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"abc\00"
define void @foo() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %1, null
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 @fclose(i32* %1)
br label %6
6: ; preds = %4, %0
%7 = icmp eq i32* %2, null
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 @fclose(i32* %2)
br label %10
10: ; preds = %8, %6
ret void
}