#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 */
char *basename(char *);
int /*<<< orphan*/ errx(int, char *);
scalar_t__ strcmp(char *, char *);
scalar_t__ test(int, char const **);
int main(int argc, char *argv[]) {
  char *base = basename(argv[0]);
  if (strcmp(base, "[") == 0) {
    if (strcmp(argv[argc - 1], "]") != 0) {
      errx(2, "missing ']'");
    }
    argc--;
  }
  return test(argc - 1, (const char **)argv + 1) ? 0 : 1;
}


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    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <basename@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe6a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11b8 <main+0x78>
mov    $0x2,%edi
lea    0xe51(%rip),%rsi
call   1030 <errx@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1060 <test@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rdi
call   1050 <basename@plt>
lea    0xea9(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1191 <main+0x51>
movslq %ebp,%rax
add    $0xffffffff,%ebp
mov    -0x8(%rbx,%rax,8),%rdi
lea    0xe8c(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1191 <main+0x51>
lea    0xe7d(%rip),%rsi
mov    $0x2,%edi
call   1030 <errx@plt>
add    $0xffffffff,%ebp
add    $0x8,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <test@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"[\00"
@.str.1 = [2 x i8] c"]\00"
@.str.2 = [12 x i8] c"missing ']'\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 i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
%10 = call i8* @basename(i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %15, i64 %18
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @errx(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %14
%26 = load i32, i32* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
br label %28
28: ; preds = %25, %2
%29 = load i32, i32* %4
%30 = sub nsw i32 %29, 1
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = call i64 @test(i32 %30, i8** %32)
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 0, i32 1
ret i32 %36
}

LLVM IR (-O2):
@.str = [2 x i8] c"[\00"
@.str.1 = [2 x i8] c"]\00"
@.str.2 = [12 x i8] c"missing ']'\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call i8* @basename(i8* %3)
%5 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = add nsw i32 %0, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %7
%15 = tail call i32 @errx(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %7, %14, %2
%17 = phi i32 [ %0, %2 ], [ %8, %14 ], [ %8, %7 ]
%18 = add nsw i32 %17, -1
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = tail call i64 @test(i32 %18, i8** %19)
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i32
ret i32 %22
}