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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int get_media_dir(char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int dir_check(char *path, char *subdir) {
  char *arg[] = {"sda1", "sda2", "sda3", "sda4", "sdb1", "sdb2",
                 "sdb3", "sdb4", "sdc1", "sdc2", "sdc3", "sdc4",
                 "sdd1", "sdd2", "sdd3", "sdd4"};
  DIR *dir;
  int i, found;
  for (i = 0; i < 16; i++) {
    found = get_media_dir(arg[i], path);
    if (found > 0)
      break;
  }
  if (found > 0) {
    i = strlen(path) - 1;
    path[i] = '\0';
    strcat(path, subdir);
    printf("path=%s\r\n", path);
  } else {
    return -1;
  }
  dir = opendir(path);
  if (dir) {
    closedir(dir);
    return 1;
  } else {
    printf("Do not find media directory(%s)\r\n", path);
    return -2;
  }
}


x86 assembly (clang, -O0):
<dir_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0x2c0f(%rip),%rsi
mov    $0x80,%edx
call   1080 <memcpy@plt>
movl   $0x0,-0xac(%rbp)
cmpl   $0x10,-0xac(%rbp)
jge    11fb <dir_check+0x8b>
movslq -0xac(%rbp),%rax
mov    -0xa0(%rbp,%rax,8),%rdi
ff
mov    -0x10(%rbp),%rsi
call   1070 <get_media_dir@plt>
mov    %eax,-0xb0(%rbp)
cmpl   $0x0,-0xb0(%rbp)
jle    11e2 <dir_check+0x72>
jmp    11fb <dir_check+0x8b>
jmp    11e7 <dir_check+0x77>
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    11a5 <dir_check+0x35>
cmpl   $0x0,-0xb0(%rbp)
jle    124b <dir_check+0xdb>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xac(%rbp)
mov    -0x10(%rbp),%rax
movslq -0xac(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rsi
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
jmp    1257 <dir_check+0xe7>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <dir_check+0x134>
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     128d <dir_check+0x11d>
mov    -0xa8(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a4 <dir_check+0x134>
mov    -0x10(%rbp),%rsi
lea    0xdc2(%rip),%rdi
call   1050 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_check>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe8f(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xe7d(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xe59(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xe47(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xe35(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xe23(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xe11(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xdff(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xded(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xddf(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xdd1(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xdc3(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xdb5(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xda7(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jg     12be <dir_check+0x15e>
lea    0xd99(%rip),%rdi
mov    %rbx,%rsi
call   1070 <get_media_dir@plt>
test   %eax,%eax
jle    131f <dir_check+0x1bf>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
lea    0xd71(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1303 <dir_check+0x1a3>
mov    %rax,%rdi
call   1060 <closedir@plt>
mov    $0x1,%eax
jmp    1317 <dir_check+0x1b7>
lea    0xd50(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffff,%eax
jmp    1317 <dir_check+0x1b7>

LLVM IR (-O0):
@.str = [5 x i8] c"sda1\00"
@.str.1 = [5 x i8] c"sda2\00"
@.str.2 = [5 x i8] c"sda3\00"
@.str.3 = [5 x i8] c"sda4\00"
@.str.4 = [5 x i8] c"sdb1\00"
@.str.5 = [5 x i8] c"sdb2\00"
@.str.6 = [5 x i8] c"sdb3\00"
@.str.7 = [5 x i8] c"sdb4\00"
@.str.8 = [5 x i8] c"sdc1\00"
@.str.9 = [5 x i8] c"sdc2\00"
@.str.10 = [5 x i8] c"sdc3\00"
@.str.11 = [5 x i8] c"sdc4\00"
@.str.12 = [5 x i8] c"sdd1\00"
@.str.13 = [5 x i8] c"sdd2\00"
@.str.14 = [5 x i8] c"sdd3\00"
@.str.15 = [5 x i8] c"sdd4\00"
@__const.dir_check.arg = [16 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i32 0, i32 0)]
@.str.16 = [10 x i8] c"path=%s\0D\0A\00"
@.str.17 = [34 x i8] c"Do not find media directory(%s)\0D\0A\00"
define i32 @dir_check(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [16 x i8*]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = bitcast [16 x i8*]* %6 to i8*
store i32 0, i32* %8
br label %11
11: ; preds = %25, %2
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 16
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [16 x i8*], [16 x i8*]* %6, i64 0, i64 %16
%18 = load i8*, i8** %17
%19 = load i8*, i8** %4
%20 = call i32 @get_media_dir(i8* %18, i8* %19)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %14
br label %28
24: ; preds = %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %11
28: ; preds = %23, %11
%29 = load i32, i32* %9
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %44
31: ; preds = %28
%32 = load i8*, i8** %4
%33 = call i32 @strlen(i8* %32)
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %8
%35 = load i8*, i8** %4
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %4
%40 = load i8*, i8** %5
%41 = call i32 @strcat(i8* %39, i8* %40)
%42 = load i8*, i8** %4
%43 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i64 0, i64 0), i8* %42)
br label %45
44: ; preds = %28
store i32 -1, i32* %3
br label %56
45: ; preds = %31
%46 = load i8*, i8** %4
%47 = call i32* @opendir(i8* %46)
store i32* %47, i32** %7
%48 = load i32*, i32** %7
%49 = icmp ne i32* %48, null
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i32*, i32** %7
%52 = call i32 @closedir(i32* %51)
store i32 1, i32* %3
br label %56
53: ; preds = %45
%54 = load i8*, i8** %4
%55 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.17, i64 0, i64 0), i8* %54)
store i32 -2, i32* %3
br label %56
56: ; preds = %53, %50, %44
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [5 x i8] c"sda1\00"
@.str.1 = [5 x i8] c"sda2\00"
@.str.2 = [5 x i8] c"sda3\00"
@.str.3 = [5 x i8] c"sda4\00"
@.str.4 = [5 x i8] c"sdb1\00"
@.str.5 = [5 x i8] c"sdb2\00"
@.str.6 = [5 x i8] c"sdb3\00"
@.str.7 = [5 x i8] c"sdb4\00"
@.str.8 = [5 x i8] c"sdc1\00"
@.str.9 = [5 x i8] c"sdc2\00"
@.str.10 = [5 x i8] c"sdc3\00"
@.str.11 = [5 x i8] c"sdc4\00"
@.str.12 = [5 x i8] c"sdd1\00"
@.str.13 = [5 x i8] c"sdd2\00"
@.str.14 = [5 x i8] c"sdd3\00"
@.str.15 = [5 x i8] c"sdd4\00"
@.str.16 = [10 x i8] c"path=%s\0D\0A\00"
@.str.17 = [34 x i8] c"Do not find media directory(%s)\0D\0A\00"
define i32 @dir_check(i8* %0, i8* %1) {
%3 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %50, label %5
5: ; preds = %2
%6 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %50, label %8
8: ; preds = %5
%9 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %50, label %11
11: ; preds = %8
%12 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %50, label %14
14: ; preds = %11
%15 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %50, label %17
17: ; preds = %14
%18 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %50, label %20
20: ; preds = %17
%21 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %50, label %23
23: ; preds = %20
%24 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %0)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %50, label %26
26: ; preds = %23
%27 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %0)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %50, label %29
29: ; preds = %26
%30 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* %0)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %50, label %32
32: ; preds = %29
%33 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* %0)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %50, label %35
35: ; preds = %32
%36 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* %0)
%37 = icmp sgt i32 %36, 0
br i1 %37, label %50, label %38
38: ; preds = %35
%39 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i8* %0)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %50, label %41
41: ; preds = %38
%42 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i8* %0)
%43 = icmp sgt i32 %42, 0
br i1 %43, label %50, label %44
44: ; preds = %41
%45 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i8* %0)
%46 = icmp sgt i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %44
%48 = tail call i32 @get_media_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0), i8* %0)
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %63
50: ; preds = %47, %44, %41, %38, %35, %32, %29, %26, %23, %20, %17, %14, %11, %8, %5, %2
%51 = tail call i32 @strlen(i8* %0)
%52 = add nsw i32 %51, -1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %0, i64 %53
store i8 0, i8* %54
%55 = tail call i32 @strcat(i8* %0, i8* %1)
%56 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i64 0, i64 0), i8* %0)
%57 = tail call i32* @opendir(i8* %0)
%58 = icmp eq i32* %57, null
br i1 %58, label %61, label %59
59: ; preds = %50
%60 = tail call i32 @closedir(i32* %57)
br label %63
61: ; preds = %50
%62 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.17, i64 0, i64 0), i8* %0)
br label %63
63: ; preds = %47, %61, %59
%64 = phi i32 [ 1, %59 ], [ -2, %61 ], [ -1, %47 ]
ret i32 %64
}