#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ ATTR_ARCH;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
char *fat_attr2string(int /*<<< orphan*/);
int /*<<< orphan*/ fat_fgetattr(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int main(int argc, char *argv[]) {
  int i, r;
  uint32_t want_add = 0;
  uint32_t want_rem = 0;
  for (i = 1; i < argc; i++) {
    char *file;
    int fd;
    uint32_t attr;
    file = argv[i];
    if (file[0] == '+' || file[0] == '-') {
      int j;
      uint32_t *want;
      for (j = 0; file[j]; j++) {
        switch (file[j]) {
        case '+':
          want = &want_add;
          break;
        case '-':
          want = &want_rem;
          break;
        case 'a':
          *want |= ATTR_ARCH;
          break;
        }
      }
    }
    fd = open(file, O_RDONLY);
    if (fd < 0)
      err(1, "could not open file");
    attr = fat_fgetattr(fd);
    printf("%s %s\n", fat_attr2string(attr), file);
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ce <main+0x16e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     11c7 <main+0x67>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1262 <main+0x102>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     125d <main+0xfd>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x44(%rbp)
sub    $0x2b,%eax
je     121f <main+0xbf>
jmp    11fd <main+0x9d>
mov    -0x44(%rbp),%eax
sub    $0x2d,%eax
je     122c <main+0xcc>
jmp    120e <main+0xae>
mov    -0x44(%rbp),%eax
sub    $0x61,%eax
je     1239 <main+0xd9>
jmp    124a <main+0xea>
lea    -0x1c(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    124a <main+0xea>
lea    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    124a <main+0xea>
mov    0x2d90(%rip),%rax
mov    (%rax),%ecx
mov    -0x40(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
jmp    124f <main+0xef>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ce <main+0x6e>
jmp    1262 <main+0x102>
mov    -0x28(%rbp),%rdi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1292 <main+0x132>
mov    $0x1,%edi
lea    0xd73(%rip),%rsi
call   1060 <err@plt>
mov    -0x2c(%rbp),%edi
call   1070 <fat_fgetattr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   1040 <fat_attr2string@plt>
mov    %rax,%rsi
mov    -0x28(%rbp),%rdx
lea    0xd61(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <main+0x2b>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
cmp    $0x2,%edi
jl     1276 <main+0x116>
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%r14d
mov    0x2e31(%rip),%r15
lea    0x4(%rsp),%r13
mov    %rsp,%rdi
jmp    1200 <main+0xa0>
nopl   0x0(%rax)
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1260 <main+0x100>
mov    %ebp,%edi
call   1070 <fat_fgetattr@plt>
mov    %eax,%edi
call   1040 <fat_attr2string@plt>
lea    0xe34(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
add    $0x1,%r14
cmp    0x8(%rsp),%r14
mov    %rsp,%rdi
je     1276 <main+0x116>
mov    0x10(%rsp),%rax
mov    (%rax,%r14,8),%rbx
mov    (%rbx),%cl
cmp    $0x2d,%cl
je     1215 <main+0xb5>
cmp    $0x2b,%cl
jne    11b0 <main+0x50>
lea    0x1(%rbx),%rax
jmp    1236 <main+0xd6>
nopl   0x0(%rax,%rax,1)
mov    (%r15),%ecx
or     %ecx,(%r12)
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
je     11b0 <main+0x50>
movsbl %cl,%ecx
cmp    $0x61,%ecx
je     1220 <main+0xc0>
cmp    $0x2d,%ecx
je     1250 <main+0xf0>
cmp    $0x2b,%ecx
jne    1227 <main+0xc7>
mov    %rdi,%r12
jmp    1227 <main+0xc7>
nopl   (%rax)
mov    %r13,%r12
jmp    1227 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
lea    0xd94(%rip),%rsi
call   1060 <err@plt>
jmp    11cb <main+0x6b>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ATTR_ARCH = global i32 0
@O_RDONLY = global i32 0
@.str = [20 x i8] c"could not open file\00"
@.str.1 = [7 x i8] c"%s %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
store i32 1, i32* %6
br label %15
15: ; preds = %80, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %83
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 43
br i1 %29, label %36, label %30
30: ; preds = %19
%31 = load i8*, i8** %10
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 45
br i1 %35, label %36, label %63
36: ; preds = %30, %19
store i32 0, i32* %13
br label %37
37: ; preds = %59, %36
%38 = load i8*, i8** %10
%39 = load i32, i32* %13
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %62
44: ; preds = %37
%45 = load i8*, i8** %10
%46 = load i32, i32* %13
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
switch i32 %50, label %58 [
i32 43, label %51
i32 45, label %52
i32 97, label %53
]
51: ; preds = %44
store i32* %8, i32** %14
br label %58
52: ; preds = %44
store i32* %9, i32** %14
br label %58
53: ; preds = %44
%54 = load i32, i32* @ATTR_ARCH
%55 = load i32*, i32** %14
%56 = load i32, i32* %55
%57 = or i32 %56, %54
store i32 %57, i32* %55
br label %58
58: ; preds = %44, %53, %52, %51
br label %59
59: ; preds = %58
%60 = load i32, i32* %13
%61 = add nsw i32 %60, 1
store i32 %61, i32* %13
br label %37
62: ; preds = %37
br label %63
63: ; preds = %62, %30
%64 = load i8*, i8** %10
%65 = load i32, i32* @O_RDONLY
%66 = call i32 @open(i8* %64, i32 %65)
store i32 %66, i32* %11
%67 = load i32, i32* %11
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %63
%70 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %71
71: ; preds = %69, %63
%72 = load i32, i32* %11
%73 = call i32 @fat_fgetattr(i32 %72)
store i32 %73, i32* %12
%74 = load i32, i32* %12
%75 = call i8* @fat_attr2string(i32 %74)
%76 = load i8*, i8** %10
%77 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %75, i8* %76)
%78 = load i32, i32* %11
%79 = call i32 @close(i32 %78)
br label %80
80: ; preds = %71
%81 = load i32, i32* %6
%82 = add nsw i32 %81, 1
store i32 %82, i32* %6
br label %15
83: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@ATTR_ARCH = global i32 0
@O_RDONLY = global i32 0
@.str = [20 x i8] c"could not open file\00"
@.str.1 = [7 x i8] c"%s %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %48
8: ; preds = %2
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %41
%11 = phi i64 [ 1, %8 ], [ %46, %41 ]
%12 = phi i32* [ undef, %8 ], [ %35, %41 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %11
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
switch i8 %15, label %34 [
i8 43, label %16
i8 45, label %16
]
16: ; preds = %10, %10
br label %17
17: ; preds = %16, %28
%18 = phi i64 [ %30, %28 ], [ 0, %16 ]
%19 = phi i8 [ %32, %28 ], [ %15, %16 ]
%20 = phi i32* [ %29, %28 ], [ %12, %16 ]
%21 = sext i8 %19 to i32
switch i32 %21, label %28 [
i32 43, label %22
i32 45, label %23
i32 97, label %24
]
22: ; preds = %17
br label %28
23: ; preds = %17
br label %28
24: ; preds = %17
%25 = load i32, i32* @ATTR_ARCH
%26 = load i32, i32* %20
%27 = or i32 %26, %25
store i32 %27, i32* %20
br label %28
28: ; preds = %22, %23, %24, %17
%29 = phi i32* [ %20, %17 ], [ %20, %24 ], [ %4, %23 ], [ %3, %22 ]
%30 = add nuw i64 %18, 1
%31 = getelementptr inbounds i8, i8* %14, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %17
34: ; preds = %28, %10
%35 = phi i32* [ %12, %10 ], [ %29, %28 ]
%36 = load i32, i32* @O_RDONLY
%37 = tail call i32 @open(i8* %14, i32 %36)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %39, %34
%42 = tail call i32 @fat_fgetattr(i32 %37)
%43 = tail call i8* @fat_attr2string(i32 %42)
%44 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %43, i8* %14)
%45 = tail call i32 @close(i32 %37)
%46 = add nuw nsw i64 %11, 1
%47 = icmp eq i64 %46, %9
br i1 %47, label %48, label %10
48: ; preds = %41, %2
ret i32 0
}