#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 */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ test_msg(char *, char *);
bool test_exists(char *mountinfo_line, char *path) {
  char aux[1024], paux[1024];
  struct stat st;
  sscanf(mountinfo_line, "%*d %*d %*d:%*d %*s %s", aux);
  test_msg("found cgroup at %s\n", aux);
  sprintf(paux, "%s/%s", aux, path);
  if (stat(paux, &st)) {
    return false;
  }
  if (!S_ISDIR(st.st_mode)) {
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<test_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xe8b(%rip),%rsi
call   1060 <sscanf@plt>
lea    -0x420(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <test_msg@plt>
lea    -0x820(%rbp),%rdi
lea    -0x420(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe85(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x820(%rbp),%rdi
lea    -0x828(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
je     11d4 <test_exists+0x84>
movl   $0x0,-0x4(%rbp)
jmp    11fb <test_exists+0xab>
mov    -0x828(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    11f4 <test_exists+0xa4>
movl   $0x0,-0x4(%rbp)
jmp    11fb <test_exists+0xab>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_exists>:
push   %r15
push   %r14
push   %rbx
sub    $0x810,%rsp
mov    %rsi,%r14
lea    0xe9a(%rip),%rsi
lea    0x410(%rsp),%rbx
mov    %rbx,%rdx
call   1060 <sscanf@plt>
lea    0xe9a(%rip),%rdi
mov    %rbx,%rsi
call   1040 <test_msg@plt>
lea    0xe9f(%rip),%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1070 <sprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1050 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11c8 <test_exists+0x78>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [23 x i8] c"%*d %*d %*d:%*d %*s %s\00"
@.str.1 = [20 x i8] c"found cgroup at %s\0A\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @test_exists(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = call i32 @test_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* %16)
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = call i64 @stat(i8* %18, %struct.stat* %8)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %2
store i32 0, i32* %3
br label %29
22: ; preds = %2
%23 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @S_ISDIR(i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
store i32 0, i32* %3
br label %29
28: ; preds = %22
store i32 1, i32* %3
br label %29
29: ; preds = %28, %27, %21
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [23 x i8] c"%*d %*d %*d:%*d %*s %s\00"
@.str.1 = [20 x i8] c"found cgroup at %s\0A\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @test_exists(i8* nocapture %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.stat* %5 to i8*
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %6)
%10 = call i32 @test_msg(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %6, i8* %1)
%12 = call i64 @stat(i8* %7, %struct.stat* %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @S_ISDIR(i32 %16)
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %14, %2
%21 = phi i32 [ 0, %2 ], [ %19, %14 ]
ret i32 %21
}