#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 */
int /*<<< orphan*/ LC_ALL;
char *dirname(char *);
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  char *p;
  int ch;
  setlocale(LC_ALL, "");
  while ((ch = getopt(argc, argv, "")) != -1)
    switch (ch) {
    case '?':
    default:
      usage();
    }
  argc -= optind;
  argv += optind;
  if (argc != 1)
    usage();
  if ((p = dirname(*argv)) == NULL)
    err(1, "%s", *argv);
  (void)printf("%s\n", p);
  exit(0);
}


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)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1060 <setlocale@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5d(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11dc <main+0x6c>
mov    -0x1c(%rbp),%eax
sub    $0x3f,%eax
jne    11d0 <main+0x60>
jmp    11cb <main+0x5b>
jmp    11d0 <main+0x60>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    119b <main+0x2b>
mov    0x2e05(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1217 <main+0xa7>
mov    $0x0,%al
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <dirname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1249 <main+0xd9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
lea    0xdbc(%rip),%rsi
call   1050 <err@plt>
mov    -0x18(%rbp),%rsi
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rbx
mov    %rbx,%rsi
call   1060 <setlocale@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1080 <getopt@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x59>
lea    0xe5c(%rip),%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <usage@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1080 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x40>
mov    0x2e18(%rip),%rax
mov    (%rax),%rbx
sub    %ebx,%ebp
cmp    $0x1,%ebp
je     11e1 <main+0x71>
xor    %eax,%eax
call   1070 <usage@plt>
mov    (%r14,%rbx,8),%rdi
call   1040 <dirname@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1207 <main+0x97>
mov    (%r14,%rbx,8),%rdx
lea    0xe03(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
lea    0xdf5(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @LC_ALL
%9 = call i32 @setlocale(i32 %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %20, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %7
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* %7
switch i32 %16, label %18 [
i32 63, label %17
]
17: ; preds = %15
br label %18
18: ; preds = %15, %17
%19 = call i32 (...) @usage()
br label %20
20: ; preds = %18
br label %10
21: ; preds = %10
%22 = load i64, i64* @optind
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = sub nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %4
%27 = load i64, i64* @optind
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 %27
store i8** %29, i8*** %5
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 (...) @usage()
br label %34
34: ; preds = %32, %21
%35 = load i8**, i8*** %5
%36 = load i8*, i8** %35
%37 = call i8* @dirname(i8* %36)
store i8* %37, i8** %6
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i8**, i8*** %5
%41 = load i8*, i8** %40
%42 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %39, %34
%44 = load i8*, i8** %6
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @LC_ALL
%4 = tail call i32 @setlocale(i32 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %2, %7
%8 = tail call i32 (...) @usage()
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %7
11: ; preds = %7, %2
%12 = load i64, i64* @optind
%13 = trunc i64 %12 to i32
%14 = sub i32 %0, %13
%15 = getelementptr inbounds i8*, i8** %1, i64 %12
%16 = icmp eq i32 %14, 1
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = tail call i32 (...) @usage()
br label %19
19: ; preds = %17, %11
%20 = load i8*, i8** %15
%21 = tail call i8* @dirname(i8* %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** %15
%25 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %19
%27 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%28 = tail call i32 @exit(i32 0)
unreachable
}