#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__ EEXIST;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ S_IRUSR;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Please supply one argument: the lock directory.\n");
    return EXIT_FAILURE;
  }
  if (mkdir(argv[1], S_IRUSR)) {
    if (errno && errno != EEXIST) {
      fprintf(stderr, "Failed to create lock %s.\n", argv[1]);
      return EXIT_FAILURE;
    }
    for (; mkdir(argv[1], S_IRUSR);) {
      sleep(1);
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1178 <main+0x48>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1238 <main+0x108>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     122c <main+0xfc>
mov    0x2e31(%rip),%rax
cmpq   $0x0,(%rax)
je     11f3 <main+0xc3>
mov    0x2e20(%rip),%rax
mov    (%rax),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
je     11f3 <main+0xc3>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1238 <main+0x108>
jmp    11f8 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     1227 <main+0xf7>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    11f8 <main+0xc8>
jmp    122c <main+0xfc>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11bd <main+0x8d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e74(%rip),%r15
mov    (%r15),%esi
call   1030 <mkdir@plt>
mov    0x2e5d(%rip),%r14
test   %rax,%rax
je     11db <main+0xab>
mov    0x2e69(%rip),%rax
mov    (%rax),%rax
test   %rax,%rax
je     11aa <main+0x7a>
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
je     11aa <main+0x7a>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xea2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d4 <main+0xa4>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    0x8(%rbx),%rdi
mov    (%r15),%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jne    11a0 <main+0x70>
jmp    11db <main+0xab>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2ded(%rip),%r14
mov    (%r14),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"Please supply one argument: the lock directory.\0A\00"
@EXIT_FAILURE = global i32 0
@S_IRUSR = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [27 x i8] c"Failed to create lock %s.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
store i32 %11, i32* %3
br label %46
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @S_IRUSR
%17 = call i64 @mkdir(i8* %15, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %44
19: ; preds = %12
%20 = load i64, i64* @errno
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = load i64, i64* @errno
%24 = load i64, i64* @EEXIST
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
store i32 %32, i32* %3
br label %46
33: ; preds = %22, %19
br label %34
34: ; preds = %41, %33
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i32, i32* @S_IRUSR
%39 = call i64 @mkdir(i8* %37, i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @sleep(i32 1)
br label %34
43: ; preds = %34
br label %44
44: ; preds = %43, %12
%45 = load i32, i32* @EXIT_SUCCESS
store i32 %45, i32* %3
br label %46
46: ; preds = %44, %26, %8
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"Please supply one argument: the lock directory.\0A\00"
@EXIT_FAILURE = global i32 0
@S_IRUSR = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [27 x i8] c"Failed to create lock %s.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %34
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @S_IRUSR
%11 = tail call i64 @mkdir(i8* %9, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %34, label %13
13: ; preds = %7
%14 = load i64, i64* @errno
%15 = icmp eq i64 %14, 0
%16 = load i64, i64* @EEXIST
%17 = icmp eq i64 %14, %16
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = load i8*, i8** %8
%21 = load i32, i32* @S_IRUSR
%22 = tail call i64 @mkdir(i8* %20, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %34, label %28
24: ; preds = %13
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %8
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %34
28: ; preds = %19, %28
%29 = tail call i32 @sleep(i32 1)
%30 = load i8*, i8** %8
%31 = load i32, i32* @S_IRUSR
%32 = tail call i64 @mkdir(i8* %30, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %28
34: ; preds = %28, %19, %7, %24, %4
%35 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_SUCCESS, %7 ], [ @EXIT_SUCCESS, %19 ], [ @EXIT_SUCCESS, %28 ]
%36 = load i32, i32* %35
ret i32 %36
}