#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 */
struct stat {
  int st_size;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int F_OK;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
scalar_t__ access(char const *, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char const *, struct stat *);
int check_dz_path(const char *path, int flag_access) {
  int tlv_size = (1 + 3);
  struct stat st_path;
  if (access(path, F_OK | flag_access) < 0) {
    printf("[utils.c|check_dz_path]file %s not exist\n", path);
    return -1;
  }
  if (stat(path, &st_path) < 0) {
    printf("[utils.c|check_dz_path] error stat \n");
    return -1;
  }
  if (!S_ISREG(st_path.st_mode)) {
    printf("[utils.c|check_dz_path]file %s not regular\n", path);
    return -1;
  }
  if (st_path.st_size < 4) {
    printf("[utils.c|check_dz_path]file %s is to large\n", path);
    return -1;
  }
  tlv_size = st_path.st_size - 4;
  return tlv_size;
}


x86 assembly (clang, -O0):
<check_dz_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x4,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
or     -0x14(%rbp),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jge    1193 <check_dz_path+0x53>
mov    -0x10(%rbp),%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <check_dz_path+0xea>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    11c4 <check_dz_path+0x84>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <check_dz_path+0xea>
mov    -0x1c(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%eax
jne    11f3 <check_dz_path+0xb3>
mov    -0x10(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <check_dz_path+0xea>
cmpl   $0x4,-0x20(%rbp)
jge    121b <check_dz_path+0xdb>
mov    -0x10(%rbp),%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <check_dz_path+0xea>
mov    -0x20(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_dz_path>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e79(%rip),%rax
or     (%rax),%esi
call   1070 <access@plt>
test   %rax,%rax
js     119c <check_dz_path+0x4c>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     11a5 <check_dz_path+0x55>
mov    0xc(%rsp),%edi
call   1060 <S_ISREG@plt>
test   %eax,%eax
je     11b3 <check_dz_path+0x63>
mov    0x8(%rsp),%eax
cmp    $0x3,%eax
jg     11cf <check_dz_path+0x7f>
lea    0xebc(%rip),%rdi
jmp    11ba <check_dz_path+0x6a>
lea    0xe5d(%rip),%rdi
jmp    11ba <check_dz_path+0x6a>
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
jmp    11c4 <check_dz_path+0x74>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
add    $0xfffffffc,%eax
jmp    11c9 <check_dz_path+0x79>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@F_OK = global i32 0
@.str = [42 x i8] c"[utils.c|check_dz_path]file %s not exist\0A\00"
@.str.1 = [37 x i8] c"[utils.c|check_dz_path] error stat \0A\00"
@.str.2 = [44 x i8] c"[utils.c|check_dz_path]file %s not regular\0A\00"
@.str.3 = [44 x i8] c"[utils.c|check_dz_path]file %s is to large\0A\00"
define i32 @check_dz_path(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 4, i32* %6
%8 = load i8*, i8** %4
%9 = load i32, i32* @F_OK
%10 = load i32, i32* %5
%11 = or i32 %9, %10
%12 = call i64 @access(i8* %8, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %43
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i64 @stat(i8* %18, %struct.stat* %7)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %43
23: ; preds = %17
%24 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%25 = load i32, i32* %24
%26 = call i32 @S_ISREG(i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 -1, i32* %3
br label %43
31: ; preds = %23
%32 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%33 = load i32, i32* %32
%34 = icmp slt i32 %33, 4
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i8*, i8** %4
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %36)
store i32 -1, i32* %3
br label %43
38: ; preds = %31
%39 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%40 = load i32, i32* %39
%41 = sub nsw i32 %40, 4
store i32 %41, i32* %6
%42 = load i32, i32* %6
store i32 %42, i32* %3
br label %43
43: ; preds = %38, %35, %28, %21, %14
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@F_OK = global i32 0
@.str = [42 x i8] c"[utils.c|check_dz_path]file %s not exist\0A\00"
@.str.2 = [44 x i8] c"[utils.c|check_dz_path]file %s not regular\0A\00"
@.str.3 = [44 x i8] c"[utils.c|check_dz_path]file %s is to large\0A\00"
@str = [36 x i8] c"[utils.c|check_dz_path] error stat \00"
define i32 @check_dz_path(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i32, i32* @F_OK
%6 = or i32 %5, %1
%7 = tail call i64 @access(i8* %0, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %31
11: ; preds = %2
%12 = call i64 @stat(i8* %0, %struct.stat* %3)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %31
16: ; preds = %11
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 @S_ISREG(i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %31
23: ; preds = %16
%24 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%25 = load i32, i32* %24
%26 = icmp slt i32 %25, 4
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %31
29: ; preds = %23
%30 = add nsw i32 %25, -4
br label %31
31: ; preds = %29, %27, %21, %14, %9
%32 = phi i32 [ -1, %9 ], [ -1, %14 ], [ -1, %27 ], [ %30, %29 ], [ -1, %21 ]
ret i32 %32
}