#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 */

/* Variables and functions */
int S_IRGRP;
int S_IRWXU;
int S_IWGRP;
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
int subdir_create(const char *root, const char *path) {
  char *subdir = NULL;
  subdir = (char *)malloc(strlen(root) + strlen(path) + 2);
  if (subdir == NULL)
    return -1;
  sprintf(subdir, "%s/%s", root, path);
  if (mkdir(subdir, S_IRWXU | S_IRGRP | S_IWGRP) != 0)
    goto error;
  free(subdir);
  return 0;
error:
  if (subdir != NULL)
    free(subdir);
  return -1;
}


x86 assembly (clang, -O0):
<subdir_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <subdir_create+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1224 <subdir_create+0xd4>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe44(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
mov    0x2dfb(%rip),%rax
or     (%rax),%esi
mov    0x2e02(%rip),%rax
or     (%rax),%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     11f4 <subdir_create+0xa4>
jmp    1209 <subdir_create+0xb9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1224 <subdir_create+0xd4>
cmpq   $0x0,-0x20(%rbp)
je     121d <subdir_create+0xcd>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subdir_create>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ca <subdir_create+0x7a>
mov    %rax,%rbx
lea    0xe79(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1070 <sprintf@plt>
mov    0x2e4c(%rip),%rax
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e32(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1040 <mkdir@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
neg    %r14
sbb    %eax,%eax
jmp    11cf <subdir_create+0x7f>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
define i32 @subdir_create(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = load i8*, i8** %5
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %8, %10
%12 = add nsw i64 %11, 2
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 -1, i32* %3
br label %42
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21)
%23 = load i8*, i8** %6
%24 = load i32, i32* @S_IRWXU
%25 = load i32, i32* @S_IRGRP
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IWGRP
%28 = or i32 %26, %27
%29 = call i64 @mkdir(i8* %23, i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %18
br label %35
32: ; preds = %18
%33 = load i8*, i8** %6
%34 = call i32 @free(i8* %33)
store i32 0, i32* %3
br label %42
35: ; preds = %31
%36 = load i8*, i8** %6
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i8*, i8** %6
%40 = call i32 @free(i8* %39)
br label %41
41: ; preds = %38, %35
store i32 -1, i32* %3
br label %42
42: ; preds = %41, %32, %17
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
define i32 @subdir_create(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %3, 2
%6 = add i64 %5, %4
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %21, label %10
10: ; preds = %2
%11 = tail call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%12 = load i32, i32* @S_IRWXU
%13 = load i32, i32* @S_IRGRP
%14 = or i32 %13, %12
%15 = load i32, i32* @S_IWGRP
%16 = or i32 %14, %15
%17 = tail call i64 @mkdir(i8* %8, i32 %16)
%18 = icmp ne i64 %17, 0
%19 = tail call i32 @free(i8* %8)
%20 = sext i1 %18 to i32
br label %21
21: ; preds = %10, %2
%22 = phi i32 [ -1, %2 ], [ %20, %10 ]
ret i32 %22
}