#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 {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
main(int argc, char **argv) {
  struct stat statbuf;
  char *filename;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s dir\n", argv[0]);
    exit(1);
  }
  filename = argv[1];
  if (stat(filename, &statbuf) < 0) {
    perror(filename);
    exit(1);
  }
  if (S_ISDIR(statbuf.st_mode)) {
    if (!opendir(filename)) {
      perror(filename);
      exit(1);
    }
  } else {
    if (open(filename, O_RDONLY) < 0) {
      perror(filename);
      exit(1);
    }
  }
  sleep(30);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c6 <main+0x46>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    11fc <main+0x7c>
mov    -0x20(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1238 <main+0xb8>
mov    -0x20(%rbp),%rdi
call   1030 <opendir@plt>
cmp    $0x0,%eax
jne    1233 <main+0xb3>
mov    -0x20(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    126c <main+0xec>
mov    -0x20(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0x0,%rax
jge    1267 <main+0xe7>
mov    -0x20(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    126c <main+0xec>
mov    $0x1e,%edi
call   10a0 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11f4 <main+0x74>
mov    0x8(%rsi),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
test   %rax,%rax
js     11e2 <main+0x62>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     11cc <main+0x4c>
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %eax,%eax
je     11e2 <main+0x62>
mov    $0x1e,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %rax,%rax
jns    11ba <main+0x3a>
mov    %rbx,%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdf9(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"Usage: %s dir\0A\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = call i64 @stat(i8* %21, %struct.stat* %6)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i8*, i8** %7
%26 = call i32 @perror(i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %17
%29 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i64 @S_ISDIR(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %28
%34 = load i8*, i8** %7
%35 = call i32 @opendir(i8* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i8*, i8** %7
%39 = call i32 @perror(i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %33
br label %52
42: ; preds = %28
%43 = load i8*, i8** %7
%44 = load i32, i32* @O_RDONLY
%45 = call i64 @open(i8* %43, i32 %44)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %42
%48 = load i8*, i8** %7
%49 = call i32 @perror(i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %42
br label %52
52: ; preds = %51, %41
%53 = call i32 @sleep(i32 30)
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"Usage: %s dir\0A\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @stat(i8* %13, %struct.stat* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 @perror(i8* %13)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i64 @S_ISDIR(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %19
%25 = call i32 @opendir(i8* %13)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = call i32 @perror(i8* %13)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = load i32, i32* @O_RDONLY
%32 = call i64 @open(i8* %13, i32 %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @perror(i8* %13)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30, %24
%38 = call i32 @sleep(i32 30)
ret i32 0
}