#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 */
scalar_t__ errno;
int mkdir(char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ strtol(char *, char **, int);
void cmd_mkdir(int argc, char *argv[]) {
  int perm = 0755;
  if (argc > 2) {
    errno = 0;
    perm = (int)strtol(argv[2], (char **)NULL, 8);
    if (errno) {
      perror("strtol");
      return;
    }
  }
  if (mkdir(argv[1], perm) == -1)
    perror("mkdir");
}


x86 assembly (clang, -O0):
<cmd_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1ed,-0x14(%rbp)
cmpl   $0x2,-0x4(%rbp)
jle    119e <cmd_mkdir+0x6e>
mov    0x2e89(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e62(%rip),%rax
cmpq   $0x0,(%rax)
je     1199 <cmd_mkdir+0x69>
lea    0xe71(%rip),%rdi
call   1050 <perror@plt>
jmp    11c3 <cmd_mkdir+0x93>
jmp    119e <cmd_mkdir+0x6e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11c3 <cmd_mkdir+0x93>
lea    0xe49(%rip),%rdi
call   1050 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_mkdir>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    $0x1ed,%esi
cmp    $0x3,%edi
jl     1168 <cmd_mkdir+0x38>
mov    0x2e98(%rip),%r14
movq   $0x0,(%r14)
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <strtol@plt>
cmpq   $0x0,(%r14)
jne    1187 <cmd_mkdir+0x57>
mov    %rax,%rsi
mov    0x8(%rbx),%rdi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
je     117e <cmd_mkdir+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe82(%rip),%rdi
jmp    118e <cmd_mkdir+0x5e>
lea    0xe72(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <perror@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [7 x i8] c"strtol\00"
@.str.1 = [6 x i8] c"mkdir\00"
define void @cmd_mkdir(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 493, i32* %5
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 2
br i1 %7, label %8, label %19
8: ; preds = %2
store i64 0, i64* @errno
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 2
%11 = load i8*, i8** %10
%12 = call i64 @strtol(i8* %11, i8** null, i32 8)
%13 = trunc i64 %12 to i32
store i32 %13, i32* %5
%14 = load i64, i64* @errno
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %28
18: ; preds = %8
br label %19
19: ; preds = %18, %2
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* %5
%24 = call i32 @mkdir(i8* %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %16, %26, %19
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [7 x i8] c"strtol\00"
@.str.1 = [6 x i8] c"mkdir\00"
define void @cmd_mkdir(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %11
4: ; preds = %2
store i64 0, i64* @errno
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i64 @strtol(i8* nocapture %6, i8** null, i32 8)
%8 = trunc i64 %7 to i32
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %4, %2
%12 = phi i32 [ %8, %4 ], [ 493, %2 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @mkdir(i8* %14, i32 %12)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %11, %4
%18 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %11 ]
%19 = tail call i32 @perror(i8* %18)
br label %20
20: ; preds = %17, %11
ret void
}