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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ memcmp(char *, char *, int);
int read(int, char *, int);
int check_file(int fd) {
  char r[sizeof("out-file-contents")];
  lseek(fd, 0, SEEK_SET);
  if (read(fd, r, sizeof(r)) != sizeof("out-file-contents"))
    return -1;
  if (memcmp(r, "out-file-contents", sizeof("out-file-contents")))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<check_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x12,%edx
call   1040 <read@plt>
cltq
cmp    $0x12,%rax
je     1177 <check_file+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <check_file+0x79>
lea    -0x20(%rbp),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x12,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     11a2 <check_file+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <check_file+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_file>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    0x2ea2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x12,%edx
call   1040 <read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x12,%ecx
jne    117b <check_file+0x4b>
lea    0xe97(%rip),%rsi
mov    %rsp,%rdi
mov    $0x12,%edx
call   1050 <memcmp@plt>
neg    %rax
sbb    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [18 x i8] c"out-file-contents\00"
define i32 @check_file(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [18 x i8]
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @SEEK_SET
%7 = call i32 @lseek(i32 %5, i32 0, i32 %6)
%8 = load i32, i32* %3
%9 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 18)
%11 = sext i32 %10 to i64
%12 = icmp ne i64 %11, 18
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %20
14: ; preds = %1
%15 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 0
%16 = call i64 @memcmp(i8* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 18)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -1, i32* %2
br label %20
19: ; preds = %14
store i32 0, i32* %2
br label %20
20: ; preds = %19, %18, %13
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [18 x i8] c"out-file-contents\00"
define i32 @check_file(i32 %0) {
%2 = alloca [18 x i8]
%3 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @lseek(i32 %0, i32 0, i32 %4)
%6 = call i32 @read(i32 %0, i8* %3, i32 18)
%7 = icmp eq i32 %6, 18
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 18)
%10 = icmp ne i64 %9, 0
%11 = sext i1 %10 to i32
br label %12
12: ; preds = %8, %1
%13 = phi i32 [ -1, %1 ], [ %11, %8 ]
ret i32 %13
}