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

/* Variables and functions */
int errno;
int getopt(int, char **, char *);
int mkdir(char *, int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ print_usage();
int strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int opt;
  char *point;
  int mode_set = 0;
  int mode = 0777;
  while (-1 != (opt = getopt(argc - 1, argv, "hm:"))) {
    switch (opt) {
    case 'h':
      print_usage();
      return 0;
    case 'm':
      mode = strtol(optarg, NULL, 8);
      mode_set = 1;
      break;
    default:
      return 0;
    }
  }
  if (argc > 1) {
    mode_t umode;
    point = argv[argc - 1];
    if (mode_set) {
      umode = umask(0);
    }
    if (-1 == mkdir(point, mode)) {
      return -errno;
    }
    if (mode_set) {
      umask(umode);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1ff,-0x28(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
lea    0xe7b(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     120b <main+0xbb>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x68,%eax
je     11c1 <main+0x71>
jmp    11b0 <main+0x60>
mov    -0x30(%rbp),%eax
sub    $0x6d,%eax
je     11d4 <main+0x84>
jmp    11fa <main+0xaa>
mov    $0x0,%al
call   1070 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    128a <main+0x13a>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1050 <strtol@plt>
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    1206 <main+0xb6>
movl   $0x0,-0x4(%rbp)
jmp    128a <main+0x13a>
jmp    1174 <main+0x24>
cmpl   $0x1,-0x8(%rbp)
jle    1283 <main+0x133>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     123e <main+0xee>
xor    %edi,%edi
call   1040 <umask@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1030 <mkdir@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    126c <main+0x11c>
xor    %eax,%eax
mov    0x2d76(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    128a <main+0x13a>
cmpl   $0x0,-0x24(%rbp)
je     127e <main+0x12e>
mov    -0x2c(%rbp),%edi
call   1040 <umask@plt>
jmp    1283 <main+0x133>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%rax
mov    %rdi,(%rsp)
lea    -0x1(%rdi),%ebp
mov    $0x1ff,%r15d
mov    $0x1,%bl
lea    0xe89(%rip),%r14
mov    0x2e7a(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
cmp    $0x6d,%eax
jne    11a9 <main+0x59>
mov    (%r12),%edi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <strtol@plt>
mov    %eax,%r15d
jmp    1180 <main+0x30>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
je     11bf <main+0x6f>
cmp    $0x68,%eax
jne    1215 <main+0xc5>
xor    %eax,%eax
call   1070 <print_usage@plt>
jmp    1215 <main+0xc5>
cmpl   $0x2,(%rsp)
jl     1215 <main+0xc5>
mov    %ebp,%eax
mov    0x0(%r13,%rax,8),%rbp
test   $0x1,%bl
je     11e3 <main+0x93>
mov    %rbp,%rdi
mov    %r15d,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1215 <main+0xc5>
jmp    1208 <main+0xb8>
xor    %r14d,%r14d
xor    %edi,%edi
call   1040 <umask@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    %r15d,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
je     1208 <main+0xb8>
mov    %ebx,%edi
call   1040 <umask@plt>
jmp    1215 <main+0xc5>
mov    0x2dc9(%rip),%rax
xor    %r14d,%r14d
sub    (%rax),%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"hm:\00"
@optarg = global i32 0
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 511, i32* %9
br label %11
11: ; preds = %25, %2
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 -1, %15
br i1 %16, label %17, label %26
17: ; preds = %11
%18 = load i32, i32* %6
switch i32 %18, label %24 [
i32 104, label %19
i32 109, label %21
]
19: ; preds = %17
%20 = call i32 (...) @print_usage()
store i32 0, i32* %3
br label %56
21: ; preds = %17
%22 = load i32, i32* @optarg
%23 = call i32 @strtol(i32 %22, i32* null, i32 8)
store i32 %23, i32* %9
store i32 1, i32* %8
br label %25
24: ; preds = %17
store i32 0, i32* %3
br label %56
25: ; preds = %21
br label %11
26: ; preds = %11
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %55
29: ; preds = %26
%30 = load i8**, i8*** %5
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %30, i64 %33
%35 = load i8*, i8** %34
store i8* %35, i8** %7
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %29
%39 = call i32 @umask(i32 0)
store i32 %39, i32* %10
br label %40
40: ; preds = %38, %29
%41 = load i8*, i8** %7
%42 = load i32, i32* %9
%43 = call i32 @mkdir(i8* %41, i32 %42)
%44 = icmp eq i32 -1, %43
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* @errno
%47 = sub nsw i32 0, %46
store i32 %47, i32* %3
br label %56
48: ; preds = %40
%49 = load i32, i32* %8
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* %10
%53 = call i32 @umask(i32 %52)
br label %54
54: ; preds = %51, %48
br label %55
55: ; preds = %54, %26
store i32 0, i32* %3
br label %56
56: ; preds = %55, %45, %24, %19
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [4 x i8] c"hm:\00"
@optarg = global i32 0
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = add nsw i32 %0, -1
br label %4
4: ; preds = %10, %2
%5 = phi i1 [ false, %10 ], [ true, %2 ]
%6 = phi i32 [ %12, %10 ], [ 511, %2 ]
%7 = tail call i32 @getopt(i32 %3, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %7, label %31 [
i32 -1, label %13
i32 104, label %8
i32 109, label %10
]
8: ; preds = %4
%9 = tail call i32 (...) @print_usage()
br label %31
10: ; preds = %4
%11 = load i32, i32* @optarg
%12 = tail call i32 @strtol(i32 %11, i32* null, i32 8)
br label %4
13: ; preds = %4
%14 = icmp sgt i32 %0, 1
br i1 %14, label %15, label %31
15: ; preds = %13
%16 = zext i32 %3 to i64
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
br i1 %5, label %19, label %22
19: ; preds = %15
%20 = tail call i32 @mkdir(i8* %18, i32 %6)
%21 = icmp eq i32 %20, -1
br i1 %21, label %28, label %31
22: ; preds = %15
%23 = tail call i32 @umask(i32 0)
%24 = tail call i32 @mkdir(i8* %18, i32 %6)
%25 = icmp eq i32 %24, -1
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = tail call i32 @umask(i32 %23)
br label %31
28: ; preds = %19, %22
%29 = load i32, i32* @errno
%30 = sub nsw i32 0, %29
br label %31
31: ; preds = %4, %19, %26, %13, %28, %8
%32 = phi i32 [ 0, %8 ], [ %30, %28 ], [ 0, %13 ], [ 0, %26 ], [ 0, %19 ], [ 0, %4 ]
ret i32 %32
}