#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 dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strstr(int /*<<< orphan*/, char *);
int get_regions(char *workdir) {
  struct dirent *e;
  DIR *d;
  char cmd[200];
  d = opendir(workdir);
  if (d) {
    while ((e = readdir(d)) != NULL) {
      if (strstr(e->d_name, ".chr")) {
        printf(" - regions retrieved .. \n");
        closedir(d);
        return 1;
      }
    }
    closedir(d);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_regions>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11de <get_regions+0x8e>
jmp    117c <get_regions+0x2c>
mov    -0x20(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d5 <get_regions+0x85>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11d0 <get_regions+0x80>
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <get_regions+0x95>
jmp    117c <get_regions+0x2c>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_regions>:
push   %rbp
push   %r14
push   %rbx
call   1040 <opendir@plt>
test   %rax,%rax
je     119f <get_regions+0x4f>
mov    %rax,%rbx
lea    0xe98(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11a3 <get_regions+0x53>
mov    (%rax),%edi
mov    %r14,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1170 <get_regions+0x20>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
jmp    11a5 <get_regions+0x55>
xor    %ebp,%ebp
jmp    11ad <get_regions+0x5d>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [5 x i8] c".chr\00"
@.str.1 = [26 x i8] c" - regions retrieved .. \0A\00"
define i32 @get_regions(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.dirent*
%5 = alloca i32*
%6 = alloca [200 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @opendir(i8* %7)
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %30
11: ; preds = %1
br label %12
12: ; preds = %26, %11
%13 = load i32*, i32** %5
%14 = call %struct.dirent* @readdir(i32* %13)
store %struct.dirent* %14, %struct.dirent** %4
%15 = icmp ne %struct.dirent* %14, null
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = load %struct.dirent*, %struct.dirent** %4
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @strstr(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32*, i32** %5
%25 = call i32 @closedir(i32* %24)
store i32 1, i32* %2
br label %31
26: ; preds = %16
br label %12
27: ; preds = %12
%28 = load i32*, i32** %5
%29 = call i32 @closedir(i32* %28)
br label %30
30: ; preds = %27, %1
store i32 0, i32* %2
br label %31
31: ; preds = %30, %22
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [5 x i8] c".chr\00"
@str = [25 x i8] c" - regions retrieved .. \00"
define i32 @get_regions(i8* nocapture %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %17, label %4
4: ; preds = %1, %7
%5 = tail call %struct.dirent* @readdir(i32* %2)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i64 @strstr(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %4, label %12
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %4, %12
%15 = phi i32 [ 1, %12 ], [ 0, %4 ]
%16 = tail call i32 @closedir(i32* %2)
br label %17
17: ; preds = %14, %1
%18 = phi i32 [ 0, %1 ], [ %15, %14 ]
ret i32 %18
}