#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
scalar_t__ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ is_file(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int check_file_1(char *file, void *data) {
  int fd;
  if (!is_file(file))
    return 0;
  fd = open(file, O_RDWR);
  if (fd < 0) {
    printf("open %s failed\n", file);
    perror("    ");
    exit(1);
  }
  if (close(fd) < 0) {
    printf("close %s failed\n", file);
    perror("    ");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_file_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <is_file@plt>
cmp    $0x0,%eax
jne    118e <check_file_1+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    1212 <check_file_1+0xb2>
mov    -0x10(%rbp),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d3 <check_file_1+0x73>
mov    -0x10(%rbp),%rsi
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
lea    0xe4c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    120b <check_file_1+0xab>
mov    -0x10(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
lea    0xe14(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_file_1>:
push   %rbx
mov    %rdi,%rbx
call   1050 <is_file@plt>
test   %eax,%eax
je     118e <check_file_1+0x2e>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1192 <check_file_1+0x32>
mov    %eax,%edi
call   1040 <close@plt>
test   %rax,%rax
js     119b <check_file_1+0x3b>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe67(%rip),%rdi
jmp    11a2 <check_file_1+0x42>
lea    0xe73(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [16 x i8] c"open %s failed\0A\00"
@.str.1 = [5 x i8] c" \00"
@.str.2 = [17 x i8] c"close %s failed\0A\00"
define i32 @check_file_1(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @is_file(i8* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %2
store i32 0, i32* %3
br label %32
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %11
%23 = load i32, i32* %6
%24 = call i64 @close(i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
store i32 0, i32* %3
br label %32
32: ; preds = %31, %10
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [16 x i8] c"open %s failed\0A\00"
@.str.1 = [5 x i8] c" \00"
@.str.2 = [17 x i8] c"close %s failed\0A\00"
define i32 @check_file_1(i8* %0, i8* nocapture readnone %1) {
%3 = tail call i32 @is_file(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %5
%14 = tail call i64 @close(i32 %7)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%18 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %13, %2
ret i32 0
}