#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 PATH_MAX;
int do_mkdir_p(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ zsnprintf(char *, int, char *, char const *, char const *);
int test_do_mkdir_p(const char *tempdir, const char *dir_name) {
  char path[PATH_MAX];
  if (zsnprintf(path, PATH_MAX, "%s/%s", tempdir, dir_name)) {
    fprintf(stderr, "path too long!\n");
    return 1;
  }
  return do_mkdir_p(path, 0775);
}


x86 assembly (clang, -O0):
<test_do_mkdir_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe7c(%rip),%rdx
call   1050 <zsnprintf@plt>
cmp    $0x0,%rax
je     11bb <test_do_mkdir_p+0x8b>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11d3 <test_do_mkdir_p+0xa3>
mov    -0x38(%rbp),%rdi
mov    $0x1fd,%esi
call   1030 <do_mkdir_p@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_do_mkdir_p>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %rsi,%r8
mov    %rdi,%rcx
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xea0(%rip),%rdx
mov    %rbx,%rdi
call   1050 <zsnprintf@plt>
test   %rax,%rax
je     1189 <test_do_mkdir_p+0x59>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    1196 <test_do_mkdir_p+0x66>
mov    %rbx,%rdi
mov    $0x1fd,%esi
call   1030 <do_mkdir_p@plt>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"path too long!\0A\00"
define i32 @test_do_mkdir_p(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32, i32* @PATH_MAX
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = call i64 @zsnprintf(i8* %12, i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %8
br label %23
21: ; preds = %2
%22 = call i32 @do_mkdir_p(i8* %12, i32 509)
store i32 %22, i32* %3
store i32 1, i32* %8
br label %23
23: ; preds = %21, %18
%24 = load i8*, i8** %6
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"path too long!\0A\00"
define i32 @test_do_mkdir_p(i8* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i64 @zsnprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %13
11: ; preds = %2
%12 = call i32 @do_mkdir_p(i8* %5, i32 509)
br label %13
13: ; preds = %11, %8
%14 = phi i32 [ 1, %8 ], [ %12, %11 ]
ret i32 %14
}