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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int dir_get(char *, char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int dir_media_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, cnt;
  cnt = (sizeof(arg) / sizeof((arg)[0]));
  for (i = 0; i < cnt; i++) {
    found = dir_get(arg[i], path);
    if (found > 0)
      break;
  }
  if (found > 0) {
    i = strlen(path) - 1;
    path[i] = '\0';
    strcat(path, subdir);
  } else {
    return -1;
  }
  dir = opendir(path);
  if (dir) {
    closedir(dir);
    return 1;
  } else {
    printf("Do not find media directory(%s)\r\n", path);
    mkdir(path, 0755);
    return -2;
  }
}


x86 assembly (clang, -O0):
<dir_media_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0x2bff(%rip),%rsi
mov    $0x80,%edx
call   1090 <memcpy@plt>
movl   $0x10,-0xb4(%rbp)
movl   $0x0,-0xac(%rbp)
mov    -0xac(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    121a <dir_media_check+0x9a>
movslq -0xac(%rbp),%rax
mov    -0xa0(%rbp,%rax,8),%rdi
ff
mov    -0x10(%rbp),%rsi
call   1080 <dir_get@plt>
mov    %eax,-0xb0(%rbp)
cmpl   $0x0,-0xb0(%rbp)
jle    1201 <dir_media_check+0x81>
jmp    121a <dir_media_check+0x9a>
jmp    1206 <dir_media_check+0x86>
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    11bf <dir_media_check+0x3f>
cmpl   $0x0,-0xb0(%rbp)
jle    125a <dir_media_check+0xda>
mov    -0x10(%rbp),%rdi
call   1050 <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   10a0 <strcat@plt>
jmp    1266 <dir_media_check+0xe6>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c1 <dir_media_check+0x141>
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     129c <dir_media_check+0x11c>
mov    -0xa8(%rbp),%rdi
call   1070 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c1 <dir_media_check+0x141>
mov    -0x10(%rbp),%rsi
lea    0xda9(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_media_check>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe7f(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xe5b(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xe49(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xe37(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xe25(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xe13(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xe01(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xdef(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xddd(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xdcf(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xdc1(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xdb3(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xda5(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xd97(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jg     12ce <dir_media_check+0x15e>
lea    0xd89(%rip),%rdi
mov    %rbx,%rsi
call   1080 <dir_get@plt>
test   %eax,%eax
jle    132d <dir_media_check+0x1bd>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1304 <dir_media_check+0x194>
mov    %rax,%rdi
call   1070 <closedir@plt>
mov    $0x1,%eax
jmp    1325 <dir_media_check+0x1b5>
lea    0xd45(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffff,%eax
jmp    1325 <dir_media_check+0x1b5>

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_media_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 = [34 x i8] c"Do not find media directory(%s)\0D\0A\00"
define i32 @dir_media_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
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = bitcast [16 x i8*]* %6 to i8*
store i32 16, i32* %10
store i32 0, i32* %8
br label %12
12: ; preds = %27, %2
%13 = load i32, i32* %8
%14 = load i32, i32* %10
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [16 x i8*], [16 x i8*]* %6, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = load i8*, i8** %4
%22 = call i32 @dir_get(i8* %20, i8* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %16
br label %30
26: ; preds = %16
br label %27
27: ; preds = %26
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %12
30: ; preds = %25, %12
%31 = load i32, i32* %9
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %30
%34 = load i8*, i8** %4
%35 = call i32 @strlen(i8* %34)
%36 = sub nsw i32 %35, 1
store i32 %36, i32* %8
%37 = load i8*, i8** %4
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
%41 = load i8*, i8** %4
%42 = load i8*, i8** %5
%43 = call i32 @strcat(i8* %41, i8* %42)
br label %45
44: ; preds = %30
store i32 -1, i32* %3
br label %58
45: ; preds = %33
%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 %58
53: ; preds = %45
%54 = load i8*, i8** %4
%55 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0), i8* %54)
%56 = load i8*, i8** %4
%57 = call i32 @mkdir(i8* %56, i32 493)
store i32 -2, i32* %3
br label %58
58: ; preds = %53, %50, %44
%59 = load i32, i32* %3
ret i32 %59
}

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 = [34 x i8] c"Do not find media directory(%s)\0D\0A\00"
define i32 @dir_media_check(i8* %0, i8* %1) {
%3 = tail call i32 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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 @dir_get(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* @opendir(i8* %0)
%57 = icmp eq i32* %56, null
br i1 %57, label %60, label %58
58: ; preds = %50
%59 = tail call i32 @closedir(i32* %56)
br label %63
60: ; preds = %50
%61 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0), i8* %0)
%62 = tail call i32 @mkdir(i8* %0, i32 493)
br label %63
63: ; preds = %47, %60, %58
%64 = phi i32 [ 1, %58 ], [ -2, %60 ], [ -1, %47 ]
ret i32 %64
}