#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_RDONLY;
int /*<<< orphan*/ get_file_size(int);
int open(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int check_and_open(const char *url, const char *document_root) {
  int fd;
  char buff[1024];
  strcpy(buff, document_root);
  if ((fd = open(strcat(buff, url), O_RDONLY)) == -1) {
    return -1;
  }
  get_file_size(fd);
  return fd;
}


x86 assembly (clang, -O0):
<check_and_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    %eax,%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    119b <check_and_open+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <check_and_open+0x69>
mov    -0x1c(%rbp),%edi
call   1040 <get_file_size@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_and_open>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1050 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1181 <check_and_open+0x41>
mov    %ebx,%edi
call   1040 <get_file_size@plt>
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @check_and_open(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %5
%10 = call i32 @strcpy(i8* %8, i8* %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i32 @strcat(i8* %11, i8* %12)
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i32 %13, i32 %14)
store i32 %15, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 -1, i32* %3
br label %22
18: ; preds = %2
%19 = load i32, i32* %6
%20 = call i32 @get_file_size(i32 %19)
%21 = load i32, i32* %6
store i32 %21, i32* %3
br label %22
22: ; preds = %18, %17
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @check_and_open(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %1)
%6 = call i32 @strcat(i8* %4, i8* %0)
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i32 %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 @get_file_size(i32 %8)
br label %12
12: ; preds = %2, %10
ret i32 %8
}