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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ do_mkdir(char *, int, 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(const char *tempdir, const char *dir_name) {
  char path[PATH_MAX], err[512] = {0};
  if (zsnprintf(path, PATH_MAX, "%s/%s", tempdir, dir_name)) {
    fprintf(stderr, "path too long!\n");
    return 1;
  }
  do_mkdir(path, 0775, err, sizeof(err));
  if (err[0])
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<test_do_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x240(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    -0x230(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    -0x240(%rbp),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe4c(%rip),%rdx
call   1060 <zsnprintf@plt>
cmp    $0x0,%rax
je     11ee <test_do_mkdir+0xae>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x234(%rbp)
jmp    123f <test_do_mkdir+0xff>
mov    -0x240(%rbp),%rdi
lea    -0x230(%rbp),%rdx
mov    $0x1fd,%esi
mov    $0x200,%ecx
call   1030 <do_mkdir@plt>
cmpb   $0x0,-0x230(%rbp)
je     122e <test_do_mkdir+0xee>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x234(%rbp)
jmp    123f <test_do_mkdir+0xff>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x234(%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>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e91(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%rbx
mov    %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x220(%rbp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xe70(%rip),%rdx
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <zsnprintf@plt>
test   %rax,%rax
je     11c2 <test_do_mkdir+0x82>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11e7 <test_do_mkdir+0xa7>
lea    -0x220(%rbp),%rdx
mov    %rbx,%rdi
mov    $0x1fd,%esi
mov    $0x200,%ecx
call   1030 <do_mkdir@plt>
xor    %eax,%eax
cmpb   $0x0,-0x220(%rbp)
setne  %al
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [512 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = bitcast [512 x i8]* %8 to i8*
%15 = load i32, i32* @PATH_MAX
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i64 @zsnprintf(i8* %13, i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %9
br label %31
23: ; preds = %2
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%25 = call i32 @do_mkdir(i8* %13, i32 509, i8* %24, i32 512)
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 1, i32* %3
store i32 1, i32* %9
br label %31
30: ; preds = %23
store i32 0, i32* %3
store i32 1, i32* %9
br label %31
31: ; preds = %30, %29, %20
%32 = load i8*, i8** %6
%33 = load i32, i32* %3
ret i32 %33
}

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(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = call i64 @zsnprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %18
13: ; preds = %2
%14 = call i32 @do_mkdir(i8* %6, i32 509, i8* %7, i32 512)
%15 = load i8, i8* %7
%16 = icmp ne i8 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %13, %10
%19 = phi i32 [ 1, %10 ], [ %17, %13 ]
ret i32 %19
}