#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 */
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int dir_check(char *dir1, char *dir2, char *dir3, char *path) {
  char buf[80] = {0};
  DIR *dir;
  dir = opendir(dir1);
  if (!dir) {
    printf("Do not find media directory(%s)\r\n", dir1);
    return -1;
  }
  strcpy(buf, dir1);
  strcat(buf, dir2);
  dir = opendir(buf);
  if (!dir) {
    if (mkdir(buf, 0755) < 0) {
      printf("Do not create directory(%s)\r\n", buf);
      return -2;
    }
  }
  strcat(buf, dir3);
  dir = opendir(buf);
  if (!dir) {
    if (mkdir(buf, 0755) < 0) {
      printf("Do not create directory(%s)\r\n", buf);
      return -3;
    }
  }
  strcpy(path, buf);
  return 0;
}


x86 assembly (clang, -O0):
<dir_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    11c5 <dir_check+0x65>
mov    -0x10(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ae <dir_check+0x14e>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x80(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    1236 <dir_check+0xd6>
lea    -0x80(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jge    1231 <dir_check+0xd1>
lea    -0x80(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1060 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12ae <dir_check+0x14e>
jmp    1236 <dir_check+0xd6>
lea    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x80(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    129a <dir_check+0x13a>
lea    -0x80(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jge    1295 <dir_check+0x135>
lea    -0x80(%rbp),%rsi
lea    0xd9e(%rip),%rdi
call   1060 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    12ae <dir_check+0x14e>
jmp    129a <dir_check+0x13a>
mov    -0x28(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_check>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
call   1050 <opendir@plt>
test   %rax,%rax
je     1202 <dir_check+0xb2>
mov    %rsp,%r13
mov    %r13,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    %r13,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
jne    11c6 <dir_check+0x76>
mov    %rsp,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
js     1218 <dir_check+0xc8>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
jne    11f3 <dir_check+0xa3>
mov    %rsp,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
js     122e <dir_check+0xde>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
jmp    1242 <dir_check+0xf2>
lea    0xdf7(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    1242 <dir_check+0xf2>
lea    0xe03(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
mov    $0xfffffffe,%eax
jmp    1242 <dir_check+0xf2>
lea    0xded(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
mov    $0xfffffffd,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Do not find media directory(%s)\0D\0A\00"
@.str.1 = [30 x i8] c"Do not create directory(%s)\0D\0A\00"
define i32 @dir_check(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [80 x i8]
%11 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = bitcast [80 x i8]* %10 to i8*
%13 = load i8*, i8** %6
%14 = call i32* @opendir(i8* %13)
store i32* %14, i32** %11
%15 = load i32*, i32** %11
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %5
br label %59
20: ; preds = %4
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%22 = load i8*, i8** %6
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%25 = load i8*, i8** %7
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%28 = call i32* @opendir(i8* %27)
store i32* %28, i32** %11
%29 = load i32*, i32** %11
%30 = icmp ne i32* %29, null
br i1 %30, label %39, label %31
31: ; preds = %20
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%33 = call i64 @mkdir(i8* %32, i32 493)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %36)
store i32 -2, i32* %5
br label %59
38: ; preds = %31
br label %39
39: ; preds = %38, %20
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%41 = load i8*, i8** %8
%42 = call i32 @strcat(i8* %40, i8* %41)
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%44 = call i32* @opendir(i8* %43)
store i32* %44, i32** %11
%45 = load i32*, i32** %11
%46 = icmp ne i32* %45, null
br i1 %46, label %55, label %47
47: ; preds = %39
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%49 = call i64 @mkdir(i8* %48, i32 493)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%53 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %52)
store i32 -3, i32* %5
br label %59
54: ; preds = %47
br label %55
55: ; preds = %54, %39
%56 = load i8*, i8** %9
%57 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%58 = call i32 @strcpy(i8* %56, i8* %57)
store i32 0, i32* %5
br label %59
59: ; preds = %55, %51, %35, %17
%60 = load i32, i32* %5
ret i32 %60
}

LLVM IR (-O2):
@.str = [34 x i8] c"Do not find media directory(%s)\0D\0A\00"
@.str.1 = [30 x i8] c"Do not create directory(%s)\0D\0A\00"
define i32 @dir_check(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [80 x i8]
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%7 = tail call i32* @opendir(i8* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %32
11: ; preds = %4
%12 = call i32 @strcpy(i8* %6, i8* %0)
%13 = call i32 @strcat(i8* %6, i8* %1)
%14 = call i32* @opendir(i8* %6)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = call i64 @mkdir(i8* %6, i32 493)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %32
21: ; preds = %16, %11
%22 = call i32 @strcat(i8* %6, i8* %2)
%23 = call i32* @opendir(i8* %6)
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = call i64 @mkdir(i8* %6, i32 493)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %32
30: ; preds = %25, %21
%31 = call i32 @strcpy(i8* %3, i8* %6)
br label %32
32: ; preds = %30, %28, %19, %9
%33 = phi i32 [ 0, %30 ], [ -3, %28 ], [ -2, %19 ], [ -1, %9 ]
ret i32 %33
}