#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 */
struct stat {
  scalar_t__ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int O_DIRECTORY;
int O_RDONLY;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int fchmod(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fstat(int, struct stat *);
int mkdir(char *, int);
int open(char *, int);
int rmdir(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  char *dname1, *dname2;
  int fddir1, fddir2, rc;
  struct stat st1, st2;
  if (argc < 2 || argc > 3) {
    fprintf(stderr, "usage: %s dirname1 [dirname2]\n", argv[0]);
    exit(1);
  }
  dname1 = argv[1];
  if (argc == 3)
    dname2 = argv[2];
  else
    dname2 = argv[1];
  fprintf(stderr, "creating directory %s\n", dname1);
  rc = mkdir(dname1, 0744);
  if (rc == -1) {
    fprintf(stderr, "creating %s fails: %s\n", dname1, strerror(errno));
    exit(1);
  }
  fprintf(stderr, "opening directory\n");
  fddir1 = open(dname1, O_RDONLY | O_DIRECTORY);
  if (fddir1 == -1) {
    fprintf(stderr, "open %s fails: %s\n", dname1, strerror(errno));
    exit(2);
  }
  fddir2 = open(dname2, O_RDONLY | O_DIRECTORY);
  if (fddir2 == -1) {
    fprintf(stderr, "open %s fails: %s\n", dname2, strerror(errno));
    exit(3);
  }
  fprintf(stderr, "unlinking %s\n", dname1);
  rc = rmdir(dname1);
  if (rc) {
    fprintf(stderr, "unlink %s error: %s\n", dname1, strerror(errno));
    exit(4);
  }
  if (access(dname2, F_OK) == 0) {
    fprintf(stderr, "%s still exists\n", dname2);
    exit(5);
  }
  if (access(dname1, F_OK) == 0) {
    fprintf(stderr, "%s still exists\n", dname1);
    exit(6);
  }
  rc = fchmod(fddir1, 0777);
  if (rc == -1) {
    fprintf(stderr, "fchmod unlinked dir fails %s\n", strerror(errno));
    exit(7);
  }
  rc = fstat(fddir1, &st1);
  if (rc == -1) {
    fprintf(stderr, "fstat unlinked dir %s fails %s\n", dname1,
            strerror(errno));
    exit(8);
  }
  rc = fstat(fddir2, &st2);
  if (rc == -1) {
    fprintf(stderr, "fstat dir %s fails %s\n", dname2, strerror(errno));
    exit(9);
  }
  if (st1.st_mode != st2.st_mode) {
    fprintf(stderr, "fstat different value on %s and %s\n", dname1, dname2);
    exit(10);
  }
  fprintf(stderr, "Ok, everything goes well.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11bd <main+0x2d>
cmpl   $0x3,-0x8(%rbp)
jle    11e5 <main+0x55>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    120c <main+0x7c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1218 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1e4,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1292 <main+0x102>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
mov    0x2d1b(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1315 <main+0x185>
mov    0x2cf8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2cc8(%rip),%rax
mov    (%rax),%esi
mov    0x2caf(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1381 <main+0x1f1>
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xcf0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xcde(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <rmdir@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     13f6 <main+0x266>
mov    0x2c17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
lea    0xc9c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2bb7(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%rax
jne    1437 <main+0x2a7>
mov    0x2bb7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xc70(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2b76(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0x0,%rax
jne    1478 <main+0x2e8>
mov    0x2b76(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xc2f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x6,%edi
call   1090 <exit@plt>
mov    -0x24(%rbp),%edi
mov    $0x1ff,%esi
call   1060 <fchmod@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    14ca <main+0x33a>
mov    0x2b37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    0x2b23(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x80(%rbp),%edi
mov    %rax,%rdx
lea    0xbee(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x7,%edi
call   1090 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10b0 <fstat@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1533 <main+0x3a3>
mov    0x2ae6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    0x2ac4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    %rax,%rcx
lea    0xba3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   10b0 <fstat@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    159c <main+0x40c>
mov    0x2a7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    0x2a5b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rdx
mov    %rax,%rcx
lea    0xb5a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x9,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
je     15d3 <main+0x443>
mov    0x2a1f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xb3a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xa,%edi
call   1090 <exit@plt>
mov    0x29f6(%rip),%rax
mov    (%rax),%edi
lea    0xb3d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    -0x4(%rdi),%eax
cmp    $0xfffffffd,%eax
jbe    1306 <main+0x176>
mov    0x8(%rsi),%r12
mov    %r12,%r14
cmp    $0x3,%edi
jne    11ba <main+0x2a>
mov    0x10(%rsi),%r14
mov    0x2e0f(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe53(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rdi
mov    $0x1e4,%esi
call   1030 <mkdir@plt>
mov    0x0(%r13),%ebp
cmp    $0xffffffff,%eax
je     132a <main+0x19a>
lea    0xe56(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2de1(%rip),%r15
mov    0x2dca(%rip),%rbx
mov    (%rbx),%esi
or     (%r15),%esi
mov    %r12,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1358 <main+0x1c8>
mov    %eax,%ebp
mov    (%rbx),%esi
or     (%r15),%esi
mov    %r14,%rdi
call   1070 <open@plt>
mov    0x0(%r13),%ebx
cmp    $0xffffffff,%eax
je     138a <main+0x1fa>
mov    %eax,%r15d
lea    0xe29(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rdi
call   1040 <rmdir@plt>
test   %eax,%eax
jne    13b8 <main+0x228>
mov    0x2d4b(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1080 <access@plt>
test   %rax,%rax
je     13ea <main+0x25a>
mov    (%rbx),%esi
mov    %r12,%rdi
call   1080 <access@plt>
test   %rax,%rax
je     1409 <main+0x279>
mov    %ebp,%edi
mov    $0x1ff,%esi
call   1060 <fchmod@plt>
cmp    $0xffffffff,%eax
je     1428 <main+0x298>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
je     1457 <main+0x2c7>
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
je     1489 <main+0x2f9>
mov    0x10(%rsp),%rax
mov    0x0(%r13),%edi
cmp    0x8(%rsp),%rax
jne    14bb <main+0x32b>
lea    0xe32(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xce7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xcf7(%rip),%rsi
mov    %ebp,%edi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x0(%r13),%ebx
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xcef(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xcc1(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
mov    0x0(%r13),%ebx
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xcb0(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>
mov    0x0(%r13),%edi
lea    0xca1(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x5,%edi
call   1090 <exit@plt>
mov    0x0(%r13),%edi
lea    0xc82(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x6,%edi
call   1090 <exit@plt>
mov    0x0(%r13),%ebx
mov    0x2b95(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xc66(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x7,%edi
call   1090 <exit@plt>
mov    0x0(%r13),%ebx
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xc55(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1090 <exit@plt>
mov    0x0(%r13),%ebx
mov    0x2b34(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xc43(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x9,%edi
call   1090 <exit@plt>
lea    0xc3a(%rip),%rsi
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xa,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [31 x i8] c"usage: %s dirname1 [dirname2]\0A\00"
@.str.1 = [23 x i8] c"creating directory %s\0A\00"
@.str.2 = [23 x i8] c"creating %s fails: %s\0A\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"opening directory\0A\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.4 = [19 x i8] c"open %s fails: %s\0A\00"
@.str.5 = [14 x i8] c"unlinking %s\0A\00"
@.str.6 = [21 x i8] c"unlink %s error: %s\0A\00"
@F_OK = global i32 0
@.str.7 = [17 x i8] c"%s still exists\0A\00"
@.str.8 = [30 x i8] c"fchmod unlinked dir fails %s\0A\00"
@.str.9 = [32 x i8] c"fstat unlinked dir %s fails %s\0A\00"
@.str.10 = [23 x i8] c"fstat dir %s fails %s\0A\00"
@.str.11 = [36 x i8] c"fstat different value on %s and %s\0A\00"
@.str.12 = [27 x i8] c"Ok, everything goes well.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.stat
%12 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 3
br i1 %17, label %18, label %25
18: ; preds = %15, %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %15
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 3
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
store i8* %34, i8** %7
br label %39
35: ; preds = %25
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
store i8* %38, i8** %7
br label %39
39: ; preds = %35, %31
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %6
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = load i8*, i8** %6
%44 = call i32 @mkdir(i8* %43, i32 484)
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %39
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %6
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %49, i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %39
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%57 = load i8*, i8** %6
%58 = load i32, i32* @O_RDONLY
%59 = load i32, i32* @O_DIRECTORY
%60 = or i32 %58, %59
%61 = call i32 @open(i8* %57, i32 %60)
store i32 %61, i32* %8
%62 = load i32, i32* %8
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %71
64: ; preds = %54
%65 = load i32, i32* @stderr
%66 = load i8*, i8** %6
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %66, i8* %68)
%70 = call i32 @exit(i32 2)
unreachable
71: ; preds = %54
%72 = load i8*, i8** %7
%73 = load i32, i32* @O_RDONLY
%74 = load i32, i32* @O_DIRECTORY
%75 = or i32 %73, %74
%76 = call i32 @open(i8* %72, i32 %75)
store i32 %76, i32* %9
%77 = load i32, i32* %9
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %86
79: ; preds = %71
%80 = load i32, i32* @stderr
%81 = load i8*, i8** %7
%82 = load i32, i32* @errno
%83 = call i8* @strerror(i32 %82)
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %81, i8* %83)
%85 = call i32 @exit(i32 3)
unreachable
86: ; preds = %71
%87 = load i32, i32* @stderr
%88 = load i8*, i8** %6
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %88)
%90 = load i8*, i8** %6
%91 = call i32 @rmdir(i8* %90)
store i32 %91, i32* %10
%92 = load i32, i32* %10
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %101
94: ; preds = %86
%95 = load i32, i32* @stderr
%96 = load i8*, i8** %6
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %96, i8* %98)
%100 = call i32 @exit(i32 4)
unreachable
101: ; preds = %86
%102 = load i8*, i8** %7
%103 = load i32, i32* @F_OK
%104 = call i64 @access(i8* %102, i32 %103)
%105 = icmp eq i64 %104, 0
br i1 %105, label %106, label %111
106: ; preds = %101
%107 = load i32, i32* @stderr
%108 = load i8*, i8** %7
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %108)
%110 = call i32 @exit(i32 5)
unreachable
111: ; preds = %101
%112 = load i8*, i8** %6
%113 = load i32, i32* @F_OK
%114 = call i64 @access(i8* %112, i32 %113)
%115 = icmp eq i64 %114, 0
br i1 %115, label %116, label %121
116: ; preds = %111
%117 = load i32, i32* @stderr
%118 = load i8*, i8** %6
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %118)
%120 = call i32 @exit(i32 6)
unreachable
121: ; preds = %111
%122 = load i32, i32* %8
%123 = call i32 @fchmod(i32 %122, i32 511)
store i32 %123, i32* %10
%124 = load i32, i32* %10
%125 = icmp eq i32 %124, -1
br i1 %125, label %126, label %132
126: ; preds = %121
%127 = load i32, i32* @stderr
%128 = load i32, i32* @errno
%129 = call i8* @strerror(i32 %128)
%130 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %129)
%131 = call i32 @exit(i32 7)
unreachable
132: ; preds = %121
%133 = load i32, i32* %8
%134 = call i32 @fstat(i32 %133, %struct.stat* %11)
store i32 %134, i32* %10
%135 = load i32, i32* %10
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %144
137: ; preds = %132
%138 = load i32, i32* @stderr
%139 = load i8*, i8** %6
%140 = load i32, i32* @errno
%141 = call i8* @strerror(i32 %140)
%142 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i8* %139, i8* %141)
%143 = call i32 @exit(i32 8)
unreachable
144: ; preds = %132
%145 = load i32, i32* %9
%146 = call i32 @fstat(i32 %145, %struct.stat* %12)
store i32 %146, i32* %10
%147 = load i32, i32* %10
%148 = icmp eq i32 %147, -1
br i1 %148, label %149, label %156
149: ; preds = %144
%150 = load i32, i32* @stderr
%151 = load i8*, i8** %7
%152 = load i32, i32* @errno
%153 = call i8* @strerror(i32 %152)
%154 = call i32 (i32, i8*, ...) @fprintf(i32 %150, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %151, i8* %153)
%155 = call i32 @exit(i32 9)
unreachable
156: ; preds = %144
%157 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%158 = load i64, i64* %157
%159 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%160 = load i64, i64* %159
%161 = icmp ne i64 %158, %160
br i1 %161, label %162, label %168
162: ; preds = %156
%163 = load i32, i32* @stderr
%164 = load i8*, i8** %6
%165 = load i8*, i8** %7
%166 = call i32 (i32, i8*, ...) @fprintf(i32 %163, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0), i8* %164, i8* %165)
%167 = call i32 @exit(i32 10)
unreachable
168: ; preds = %156
%169 = load i32, i32* @stderr
%170 = call i32 (i32, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [31 x i8] c"usage: %s dirname1 [dirname2]\0A\00"
@.str.1 = [23 x i8] c"creating directory %s\0A\00"
@.str.2 = [23 x i8] c"creating %s fails: %s\0A\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"opening directory\0A\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.4 = [19 x i8] c"open %s fails: %s\0A\00"
@.str.5 = [14 x i8] c"unlinking %s\0A\00"
@.str.6 = [21 x i8] c"unlink %s error: %s\0A\00"
@F_OK = global i32 0
@.str.7 = [17 x i8] c"%s still exists\0A\00"
@.str.8 = [30 x i8] c"fchmod unlinked dir fails %s\0A\00"
@.str.9 = [32 x i8] c"fstat unlinked dir %s fails %s\0A\00"
@.str.10 = [23 x i8] c"fstat dir %s fails %s\0A\00"
@.str.11 = [36 x i8] c"fstat different value on %s and %s\0A\00"
@.str.12 = [27 x i8] c"Ok, everything goes well.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = add i32 %0, -4
%8 = icmp ult i32 %7, -2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = icmp eq i32 %0, 3
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
br label %21
21: ; preds = %14, %18
%22 = phi i8* [ %20, %18 ], [ %16, %14 ]
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%25 = tail call i32 @mkdir(i8* %16, i32 484)
%26 = icmp eq i32 %25, -1
%27 = load i32, i32* @stderr
br i1 %26, label %28, label %33
28: ; preds = %21
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %30)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %21
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* @O_RDONLY
%36 = load i32, i32* @O_DIRECTORY
%37 = or i32 %36, %35
%38 = tail call i32 @open(i8* %16, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %46
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = tail call i8* @strerror(i32 %42)
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %16, i8* %43)
%45 = tail call i32 @exit(i32 2)
unreachable
46: ; preds = %33
%47 = load i32, i32* @O_RDONLY
%48 = load i32, i32* @O_DIRECTORY
%49 = or i32 %48, %47
%50 = tail call i32 @open(i8* %22, i32 %49)
%51 = icmp eq i32 %50, -1
%52 = load i32, i32* @stderr
br i1 %51, label %53, label %58
53: ; preds = %46
%54 = load i32, i32* @errno
%55 = tail call i8* @strerror(i32 %54)
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %22, i8* %55)
%57 = tail call i32 @exit(i32 3)
unreachable
58: ; preds = %46
%59 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %16)
%60 = tail call i32 @rmdir(i8* %16)
%61 = icmp eq i32 %60, 0
br i1 %61, label %68, label %62
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = tail call i8* @strerror(i32 %64)
%66 = tail call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %16, i8* %65)
%67 = tail call i32 @exit(i32 4)
unreachable
68: ; preds = %58
%69 = load i32, i32* @F_OK
%70 = tail call i64 @access(i8* %22, i32 %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %68
%73 = load i32, i32* @stderr
%74 = tail call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %22)
%75 = tail call i32 @exit(i32 5)
unreachable
76: ; preds = %68
%77 = load i32, i32* @F_OK
%78 = tail call i64 @access(i8* %16, i32 %77)
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %76
%81 = load i32, i32* @stderr
%82 = tail call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %16)
%83 = tail call i32 @exit(i32 6)
unreachable
84: ; preds = %76
%85 = tail call i32 @fchmod(i32 %38, i32 511)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %93
87: ; preds = %84
%88 = load i32, i32* @stderr
%89 = load i32, i32* @errno
%90 = tail call i8* @strerror(i32 %89)
%91 = tail call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %90)
%92 = tail call i32 @exit(i32 7)
unreachable
93: ; preds = %84
%94 = call i32 @fstat(i32 %38, %struct.stat* %3)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %102
96: ; preds = %93
%97 = load i32, i32* @stderr
%98 = load i32, i32* @errno
%99 = tail call i8* @strerror(i32 %98)
%100 = tail call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i8* %16, i8* %99)
%101 = tail call i32 @exit(i32 8)
unreachable
102: ; preds = %93
%103 = call i32 @fstat(i32 %50, %struct.stat* %4)
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %111
105: ; preds = %102
%106 = load i32, i32* @stderr
%107 = load i32, i32* @errno
%108 = tail call i8* @strerror(i32 %107)
%109 = tail call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %22, i8* %108)
%110 = tail call i32 @exit(i32 9)
unreachable
111: ; preds = %102
%112 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%113 = load i64, i64* %112
%114 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%115 = load i64, i64* %114
%116 = icmp eq i64 %113, %115
%117 = load i32, i32* @stderr
br i1 %116, label %121, label %118
118: ; preds = %111
%119 = tail call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0), i8* %16, i8* %22)
%120 = tail call i32 @exit(i32 10)
unreachable
121: ; preds = %111
%122 = tail call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0))
ret i32 0
}