#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int stat(char const *, struct stat *);
int get_path_infos(const char *path, struct stat *st, int *flag) {
  int ret;
  ret = stat(path, st);
  if (ret < 0) {
    *flag = 5;
    return -1;
  }
  if (S_ISREG(st->st_mode))
    *flag = 1;
  else if (S_ISDIR(st->st_mode))
    *flag = 2;
  return ret;
}


x86 assembly (clang, -O0):
<get_path_infos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1174 <get_path_infos+0x44>
mov    -0x20(%rbp),%rax
movl   $0x5,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <get_path_infos+0x92>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     1198 <get_path_infos+0x68>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
jmp    11bc <get_path_infos+0x8c>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11b7 <get_path_infos+0x87>
mov    -0x20(%rbp),%rax
movl   $0x2,(%rax)
jmp    11bc <get_path_infos+0x8c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_path_infos>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
call   1040 <stat@plt>
test   %eax,%eax
js     1169 <get_path_infos+0x39>
mov    %eax,%ebp
mov    (%rbx),%edi
call   1050 <S_ISREG@plt>
mov    $0x1,%ecx
test   %rax,%rax
jne    1173 <get_path_infos+0x43>
mov    (%rbx),%edi
call   1030 <S_ISDIR@plt>
mov    $0x2,%ecx
test   %rax,%rax
jne    1173 <get_path_infos+0x43>
jmp    1176 <get_path_infos+0x46>
mov    $0xffffffff,%ebp
mov    $0x5,%ecx
mov    %ecx,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @get_path_infos(i8* %0, %struct.stat* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.stat*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %5
store %struct.stat* %1, %struct.stat** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = load %struct.stat*, %struct.stat** %6
%11 = call i32 @stat(i8* %9, %struct.stat* %10)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i32*, i32** %7
store i32 5, i32* %15
store i32 -1, i32* %4
br label %35
16: ; preds = %3
%17 = load %struct.stat*, %struct.stat** %6
%18 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @S_ISREG(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = load i32*, i32** %7
store i32 1, i32* %23
br label %33
24: ; preds = %16
%25 = load %struct.stat*, %struct.stat** %6
%26 = getelementptr inbounds %struct.stat, %struct.stat* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i64 @S_ISDIR(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = load i32*, i32** %7
store i32 2, i32* %31
br label %32
32: ; preds = %30, %24
br label %33
33: ; preds = %32, %22
%34 = load i32, i32* %8
store i32 %34, i32* %4
br label %35
35: ; preds = %33, %14
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @get_path_infos(i8* nocapture %0, %struct.stat* nocapture %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @stat(i8* %0, %struct.stat* %1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @S_ISREG(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i32, i32* %7
%13 = tail call i64 @S_ISDIR(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11, %6, %3
%16 = phi i32 [ 5, %3 ], [ 1, %6 ], [ 2, %11 ]
%17 = phi i32 [ -1, %3 ], [ %4, %6 ], [ %4, %11 ]
store i32 %16, i32* %2
br label %18
18: ; preds = %15, %11
%19 = phi i32 [ %4, %11 ], [ %17, %15 ]
ret i32 %19
}