#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*/ bu_extra_argument(char *);
scalar_t__ bu_handle_version(int, char **);
int /*<<< orphan*/ bu_missing_argument(char *);
scalar_t__ consists_entirely_of(char *, char);
scalar_t__ has_arg(int, char **, char *);
int /*<<< orphan*/ has_slash(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ truncate_trailing_non_slashes(char *);
int /*<<< orphan*/ truncate_trailing_slashes(char *);
int main(int argc, char **argv) {
  if (has_arg(argc, argv, "-h") || has_arg(argc, argv, "--help")) {
    puts("Usage: dirname PATH");
    puts("Strip the last component of a file path.");
    return 1;
  }
  if (bu_handle_version(argc, argv)) {
    return 0;
  }
  if (argc < 2) {
    bu_missing_argument(argv[0]);
    return 1;
  }
  if (argc > 2) {
    bu_extra_argument(argv[0]);
    return 1;
  }
  char *string = argv[1];
  if (strncmp("//", string, 3) == 0) {
    puts("/");
    return 0;
  }
  if (consists_entirely_of(string, '/')) {
    puts("/");
    return 0;
  }
  truncate_trailing_slashes(string);
  if (!has_slash(string)) {
    puts(".");
    return 0;
  }
  truncate_trailing_non_slashes(string);
  truncate_trailing_slashes(string);
  if (strlen(string) == 0) {
    puts("/");
    return 0;
  }
  puts(string);
  return 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    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2c(%rip),%rdx
call   1050 <has_arg@plt>
cmp    $0x0,%rax
jne    1200 <main+0x50>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe12(%rip),%rdx
call   1050 <has_arg@plt>
cmp    $0x0,%rax
je     1224 <main+0x74>
lea    0xe03(%rip),%rdi
call   1040 <puts@plt>
lea    0xe0b(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    137d <main+0x1cd>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10c0 <bu_handle_version@plt>
cmp    $0x0,%rax
je     1246 <main+0x96>
movl   $0x0,-0x4(%rbp)
jmp    137d <main+0x1cd>
cmpl   $0x2,-0x8(%rbp)
jge    1268 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10d0 <bu_missing_argument@plt>
movl   $0x1,-0x4(%rbp)
jmp    137d <main+0x1cd>
cmpl   $0x2,-0x8(%rbp)
jle    128a <main+0xda>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <bu_extra_argument@plt>
movl   $0x1,-0x4(%rbp)
jmp    137d <main+0x1cd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xda6(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12cd <main+0x11d>
lea    0xd8c(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    137d <main+0x1cd>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <consists_entirely_of@plt>
cmp    $0x0,%rax
je     12fd <main+0x14d>
lea    0xd5c(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    137d <main+0x1cd>
mov    -0x18(%rbp),%rdi
call   10a0 <truncate_trailing_slashes@plt>
mov    -0x18(%rbp),%rdi
call   1070 <has_slash@plt>
cmp    $0x0,%eax
jne    1330 <main+0x180>
lea    0xd26(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    137d <main+0x1cd>
mov    -0x18(%rbp),%rdi
call   10b0 <truncate_trailing_non_slashes@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <truncate_trailing_slashes@plt>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
jne    136d <main+0x1bd>
lea    0xcec(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    137d <main+0x1cd>
mov    -0x18(%rbp),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe4d(%rip),%rdx
call   1050 <has_arg@plt>
test   %rax,%rax
jne    11d3 <main+0x33>
lea    0xe3f(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <has_arg@plt>
test   %rax,%rax
je     11ff <main+0x5f>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
call   10b0 <bu_handle_version@plt>
xor    %r15d,%r15d
test   %rax,%rax
jne    11f1 <main+0x51>
cmp    $0x1,%ebp
jg     1220 <main+0x80>
mov    (%rbx),%rdi
call   10c0 <bu_missing_argument@plt>
jmp    11eb <main+0x4b>
cmp    $0x2,%ebp
jne    1262 <main+0xc2>
mov    0x8(%rbx),%r14
lea    0xe17(%rip),%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1254 <main+0xb4>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1070 <consists_entirely_of@plt>
test   %rax,%rax
je     126f <main+0xcf>
lea    0xded(%rip),%rdi
call   1040 <puts@plt>
jmp    11f1 <main+0x51>
mov    (%rbx),%rdi
call   1080 <bu_extra_argument@plt>
jmp    11eb <main+0x4b>
mov    %r14,%rdi
call   1090 <truncate_trailing_slashes@plt>
mov    %r14,%rdi
call   1060 <has_slash@plt>
test   %eax,%eax
je     129e <main+0xfe>
mov    %r14,%rdi
call   10a0 <truncate_trailing_non_slashes@plt>
mov    %r14,%rdi
call   1090 <truncate_trailing_slashes@plt>
cmpb   $0x0,(%r14)
je     1254 <main+0xb4>
mov    %r14,%rdi
jmp    125b <main+0xbb>
lea    0xda0(%rip),%rdi
jmp    125b <main+0xbb>

LLVM IR (-O0):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [20 x i8] c"Usage: dirname PATH\00"
@.str.3 = [41 x i8] c"Strip the last component of a file path.\00"
@.str.4 = [3 x i8] c"//\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = load i8**, i8*** %5
%9 = call i64 @has_arg(i32 %7, i8** %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i64 @has_arg(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11, %2
%17 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @puts(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %77
19: ; preds = %11
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i64 @bu_handle_version(i32 %20, i8** %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %3
br label %77
25: ; preds = %19
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 2
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @bu_missing_argument(i8* %31)
store i32 1, i32* %3
br label %77
33: ; preds = %25
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 2
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @bu_extra_argument(i8* %39)
store i32 1, i32* %3
br label %77
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
store i8* %44, i8** %6
%45 = load i8*, i8** %6
%46 = call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %45, i32 3)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %41
%49 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %77
50: ; preds = %41
%51 = load i8*, i8** %6
%52 = call i64 @consists_entirely_of(i8* %51, i8 signext 47)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %77
56: ; preds = %50
%57 = load i8*, i8** %6
%58 = call i32 @truncate_trailing_slashes(i8* %57)
%59 = load i8*, i8** %6
%60 = call i32 @has_slash(i8* %59)
%61 = icmp ne i32 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %56
%63 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %77
64: ; preds = %56
%65 = load i8*, i8** %6
%66 = call i32 @truncate_trailing_non_slashes(i8* %65)
%67 = load i8*, i8** %6
%68 = call i32 @truncate_trailing_slashes(i8* %67)
%69 = load i8*, i8** %6
%70 = call i64 @strlen(i8* %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %64
%73 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %77
74: ; preds = %64
%75 = load i8*, i8** %6
%76 = call i32 @puts(i8* %75)
store i32 0, i32* %3
br label %77
77: ; preds = %74, %72, %62, %54, %48, %36, %28, %24, %16
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [20 x i8] c"Usage: dirname PATH\00"
@.str.3 = [41 x i8] c"Strip the last component of a file path.\00"
@.str.4 = [3 x i8] c"//\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i64 @has_arg(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5, %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %51
11: ; preds = %5
%12 = tail call i64 @bu_handle_version(i32 %0, i8** %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %51
14: ; preds = %11
%15 = icmp slt i32 %0, 2
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = load i8*, i8** %1
%18 = tail call i32 @bu_missing_argument(i8* %17)
br label %51
19: ; preds = %14
%20 = icmp eq i32 %0, 2
br i1 %20, label %24, label %21
21: ; preds = %19
%22 = load i8*, i8** %1
%23 = tail call i32 @bu_extra_argument(i8* %22)
br label %51
24: ; preds = %19
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i64 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %26, i32 3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %51
31: ; preds = %24
%32 = tail call i64 @consists_entirely_of(i8* %26, i8 signext 47)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %51
36: ; preds = %31
%37 = tail call i32 @truncate_trailing_slashes(i8* %26)
%38 = tail call i32 @has_slash(i8* %26)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %51
42: ; preds = %36
%43 = tail call i32 @truncate_trailing_non_slashes(i8* %26)
%44 = tail call i32 @truncate_trailing_slashes(i8* %26)
%45 = load i8, i8* %26
%46 = icmp eq i8 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %51
49: ; preds = %42
%50 = tail call i32 @puts(i8* %26)
br label %51
51: ; preds = %29, %34, %40, %47, %49, %11, %21, %16, %8
%52 = phi i32 [ 1, %8 ], [ 1, %16 ], [ 1, %21 ], [ 0, %11 ], [ 0, %49 ], [ 0, %47 ], [ 0, %40 ], [ 0, %34 ], [ 0, %29 ]
ret i32 %52
}