#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 st_mode;
};

/* Variables and functions */
int EXIT_SUCCESS;
scalar_t__ S_ISDIR(int);
int /*<<< orphan*/ errexit(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  int group, offset, file;
  struct stat s;
  char output[11] = "----------";
  if (argc < 2)
    errexit("Usage: fprm FILE...");
  for (file = 1; file < argc; file++) {
    if (stat(argv[file], &s) == -1)
      errexit("fprm: stat() failed");
    if (S_ISDIR(s.st_mode))
      output[0] = 'd';
    for (group = 0100, offset = 0; group >= 1; group /= 010, offset += 3) {
      if (s.st_mode & (group * 4))
        output[1 + offset] = 'r';
      if (s.st_mode & (group * 2))
        output[2 + offset] = 'w';
      if (s.st_mode & group)
        output[3 + offset] = 'x';
    }
    if (argc > 2)
      printf("%s: ", argv[file]);
    puts(output);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x2b(%rbp)
mov    0xe90(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xe88(%rip),%al
mov    %al,-0x21(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119b <main+0x4b>
lea    0xe75(%rip),%rdi
call   1060 <errexit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12be <main+0x16e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    11d8 <main+0x88>
lea    0xe4c(%rip),%rdi
call   1060 <errexit@plt>
mov    -0x20(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11ee <main+0x9e>
movb   $0x64,-0x2b(%rbp)
movl   $0x40,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     1285 <main+0x135>
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1227 <main+0xd7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x72,-0x2b(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1248 <main+0xf8>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
cltq
movb   $0x77,-0x2b(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
and    -0x14(%rbp),%eax
cmp    $0x0,%eax
je     1264 <main+0x114>
mov    -0x18(%rbp),%eax
add    $0x3,%eax
cltq
movb   $0x78,-0x2b(%rbp,%rax,1)
jmp    1269 <main+0x119>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x18(%rbp)
jmp    11fc <main+0xac>
cmpl   $0x2,-0x8(%rbp)
jle    12a7 <main+0x157>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd91(%rip),%rdi
call   1040 <printf@plt>
lea    -0x2b(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a2 <main+0x52>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x2d2d2d2d2d2d2d2d,%rax
2d 2d 2d
mov    %rax,(%rsp)
movl   $0x2d2d2d,0x7(%rsp)
cmp    $0x1,%edi
jg     119d <main+0x4d>
lea    0xe8b(%rip),%rdi
call   1060 <errexit@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edi,%r13d
mov    $0x1,%r14d
mov    %rsp,%r12
jmp    11c1 <main+0x71>
mov    %r12,%rdi
call   1030 <puts@plt>
add    $0x1,%r14
cmp    %r14,%r13
je     1185 <main+0x35>
mov    (%rbx,%r14,8),%rdi
lea    0x10(%rsp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x90>
lea    0xe44(%rip),%rdi
call   1060 <errexit@plt>
mov    0x10(%rsp),%r15d
mov    %r15d,%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     11f6 <main+0xa6>
movb   $0x64,(%rsp)
test   $0x100,%r15d
jne    1240 <main+0xf0>
test   $0x80,%r15b
jne    124b <main+0xfb>
test   $0x40,%r15b
jne    1256 <main+0x106>
test   $0x20,%r15b
jne    1261 <main+0x111>
test   $0x10,%r15b
jne    126c <main+0x11c>
test   $0x8,%r15b
jne    1277 <main+0x127>
test   $0x4,%r15b
jne    1282 <main+0x132>
test   $0x2,%r15b
jne    128d <main+0x13d>
test   $0x1,%r15b
jne    1298 <main+0x148>
cmp    $0x2,%ebp
je     11b0 <main+0x60>
jmp    12a6 <main+0x156>
nopw   0x0(%rax,%rax,1)
movb   $0x72,0x1(%rsp)
test   $0x80,%r15b
je     1205 <main+0xb5>
movb   $0x77,0x2(%rsp)
test   $0x40,%r15b
je     120b <main+0xbb>
movb   $0x78,0x3(%rsp)
test   $0x20,%r15b
je     1211 <main+0xc1>
movb   $0x72,0x4(%rsp)
test   $0x10,%r15b
je     1217 <main+0xc7>
movb   $0x77,0x5(%rsp)
test   $0x8,%r15b
je     121d <main+0xcd>
movb   $0x78,0x6(%rsp)
test   $0x4,%r15b
je     1223 <main+0xd3>
movb   $0x72,0x7(%rsp)
test   $0x2,%r15b
je     1229 <main+0xd9>
movb   $0x77,0x8(%rsp)
test   $0x1,%r15b
je     122f <main+0xdf>
movb   $0x78,0x9(%rsp)
cmp    $0x2,%ebp
je     11b0 <main+0x60>
mov    (%rbx,%r14,8),%rsi
lea    0xd82(%rip),%rdi
call   1040 <printf@plt>
jmp    11b0 <main+0x60>

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.main.output = [11 x i8] c"----------\00"
@.str = [20 x i8] c"Usage: fprm FILE...\00"
@.str.1 = [20 x i8] c"fprm: stat() failed\00"
@.str.2 = [5 x i8] c"%s: \00"
@EXIT_SUCCESS = global i32 0
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 %struct.stat
%10 = alloca [11 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [11 x i8]* %10 to i8*
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @errexit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
store i32 1, i32* %8
br label %17
17: ; preds = %96, %16
%18 = load i32, i32* %8
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %99
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @stat(i8* %26, %struct.stat* %9)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %21
%30 = call i32 @errexit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %21
%32 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i64 @S_ISDIR(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = getelementptr inbounds [11 x i8], [11 x i8]* %10, i64 0, i64 0
store i8 100, i8* %37
br label %38
38: ; preds = %36, %31
store i32 64, i32* %6
store i32 0, i32* %7
br label %39
39: ; preds = %78, %38
%40 = load i32, i32* %6
%41 = icmp sge i32 %40, 1
br i1 %41, label %42, label %83
42: ; preds = %39
%43 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%44 = load i32, i32* %43
%45 = load i32, i32* %6
%46 = mul nsw i32 %45, 4
%47 = and i32 %44, %46
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %42
%50 = load i32, i32* %7
%51 = add nsw i32 1, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [11 x i8], [11 x i8]* %10, i64 0, i64 %52
store i8 114, i8* %53
br label %54
54: ; preds = %49, %42
%55 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%56 = load i32, i32* %55
%57 = load i32, i32* %6
%58 = mul nsw i32 %57, 2
%59 = and i32 %56, %58
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %54
%62 = load i32, i32* %7
%63 = add nsw i32 2, %62
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [11 x i8], [11 x i8]* %10, i64 0, i64 %64
store i8 119, i8* %65
br label %66
66: ; preds = %61, %54
%67 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%68 = load i32, i32* %67
%69 = load i32, i32* %6
%70 = and i32 %68, %69
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %66
%73 = load i32, i32* %7
%74 = add nsw i32 3, %73
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [11 x i8], [11 x i8]* %10, i64 0, i64 %75
store i8 120, i8* %76
br label %77
77: ; preds = %72, %66
br label %78
78: ; preds = %77
%79 = load i32, i32* %6
%80 = sdiv i32 %79, 8
store i32 %80, i32* %6
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 3
store i32 %82, i32* %7
br label %39
83: ; preds = %39
%84 = load i32, i32* %4
%85 = icmp sgt i32 %84, 2
br i1 %85, label %86, label %93
86: ; preds = %83
%87 = load i8**, i8*** %5
%88 = load i32, i32* %8
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8*, i8** %87, i64 %89
%91 = load i8*, i8** %90
%92 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %91)
br label %93
93: ; preds = %86, %83
%94 = getelementptr inbounds [11 x i8], [11 x i8]* %10, i64 0, i64 0
%95 = call i32 @puts(i8* %94)
br label %96
96: ; preds = %93
%97 = load i32, i32* %8
%98 = add nsw i32 %97, 1
store i32 %98, i32* %8
br label %17
99: ; preds = %17
%100 = load i32, i32* @EXIT_SUCCESS
ret i32 %100
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@__const.main.output = [11 x i8] c"----------\00"
@.str = [20 x i8] c"Usage: fprm FILE...\00"
@.str.1 = [20 x i8] c"fprm: stat() failed\00"
@.str.2 = [5 x i8] c"%s: \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca [11 x i8]
%5 = bitcast %struct.stat* %3 to i8*
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @errexit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %80
10: ; preds = %2
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = icmp eq i32 %0, 2
%13 = zext i32 %0 to i64
%14 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 1
%15 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 2
%16 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 3
%17 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 4
%18 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 5
%19 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 6
%20 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 7
%21 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 8
%22 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 9
br label %23
23: ; preds = %10, %76
%24 = phi i64 [ 1, %10 ], [ %78, %76 ]
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @stat(i8* %26, %struct.stat* %3)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = tail call i32 @errexit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
%32 = load i32, i32* %11
%33 = tail call i64 @S_ISDIR(i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %31
store i8 100, i8* %6
br label %36
36: ; preds = %35, %31
%37 = and i32 %32, 256
%38 = icmp eq i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %36
store i8 114, i8* %14
br label %40
40: ; preds = %39, %36
%41 = and i32 %32, 128
%42 = icmp eq i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %40
store i8 119, i8* %15
br label %44
44: ; preds = %43, %40
%45 = and i32 %32, 64
%46 = icmp eq i32 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %44
store i8 120, i8* %16
br label %48
48: ; preds = %44, %47
%49 = and i32 %32, 32
%50 = icmp eq i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %48
store i8 114, i8* %17
br label %52
52: ; preds = %51, %48
%53 = and i32 %32, 16
%54 = icmp eq i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %52
store i8 119, i8* %18
br label %56
56: ; preds = %55, %52
%57 = and i32 %32, 8
%58 = icmp eq i32 %57, 0
br i1 %58, label %60, label %59
59: ; preds = %56
store i8 120, i8* %19
br label %60
60: ; preds = %59, %56
%61 = and i32 %32, 4
%62 = icmp eq i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %60
store i8 114, i8* %20
br label %64
64: ; preds = %63, %60
%65 = and i32 %32, 2
%66 = icmp eq i32 %65, 0
br i1 %66, label %68, label %67
67: ; preds = %64
store i8 119, i8* %21
br label %68
68: ; preds = %67, %64
%69 = and i32 %32, 1
%70 = icmp eq i32 %69, 0
br i1 %70, label %72, label %71
71: ; preds = %68
store i8 120, i8* %22
br label %72
72: ; preds = %71, %68
br i1 %12, label %76, label %73
73: ; preds = %72
%74 = load i8*, i8** %25
%75 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %73, %72
%77 = call i32 @puts(i8* %6)
%78 = add nuw nsw i64 %24, 1
%79 = icmp eq i64 %78, %13
br i1 %79, label %80, label %23
80: ; preds = %76, %8
%81 = load i32, i32* @EXIT_SUCCESS
ret i32 %81
}