#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 */
scalar_t__ chmod(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int strtoul(char *, char **, int);
int nfschmod(int argc, char **argv) {
  int mode, c;
  char *name, *end;
  while ((c = getopt(argc, argv, "")) != -1) {
    switch (c) {
    default:
      fprintf(stderr, "Invalid option\n");
      return 1;
    }
  }
  if (optind < argc - 2) {
    fprintf(stderr, "missing mode and/or file name\n");
    return 1;
  }
  mode = strtoul(argv[optind], &end, 8);
  if (*end) {
    fprintf(stderr, "bad file mode \"%s\"\n", argv[optind]);
    return 1;
  }
  optind++;
  while (optind < argc) {
    name = argv[optind++];
    if (chmod(name, mode) < 0)
      perror(name);
  }
  return 0;
}


x86 assembly (clang, -O0):
<nfschmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xed5(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     11a1 <nfschmod+0x51>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b8 <nfschmod+0x168>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    11db <nfschmod+0x8b>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b8 <nfschmod+0x168>
mov    -0x10(%rbp),%rax
mov    0x2e02(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     1240 <nfschmod+0xf0>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2dc9(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b8 <nfschmod+0x168>
mov    0x2da1(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2d95(%rip),%rax
mov    %ecx,(%rax)
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    12b1 <nfschmod+0x161>
mov    -0x10(%rbp),%rax
mov    0x2d76(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2d68(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <chmod@plt>
cmp    $0x0,%rax
jge    12ac <nfschmod+0x15c>
mov    -0x20(%rbp),%rdi
call   1050 <perror@plt>
jmp    1255 <nfschmod+0x105>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nfschmod>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xedb(%rip),%rdx
call   1060 <getopt@plt>
cmp    $0xffffffff,%eax
je     1183 <nfschmod+0x33>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
jmp    11a5 <nfschmod+0x55>
mov    0x2e5e(%rip),%r13
movslq 0x0(%r13),%rax
lea    -0x2(%rbx),%ecx
cmp    %ecx,%eax
jge    11c4 <nfschmod+0x74>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14,%rax,8),%rdi
mov    %rsp,%rsi
mov    $0x8,%edx
call   1070 <strtoul@plt>
mov    %eax,%r15d
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     1202 <nfschmod+0xb2>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
movslq 0x0(%r13),%rax
mov    (%r14,%rax,8),%rdx
lea    0xe36(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11ac <nfschmod+0x5c>
mov    0x0(%r13),%eax
add    $0x1,%eax
mov    %eax,0x0(%r13)
xor    %r12d,%r12d
jmp    1224 <nfschmod+0xd4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%eax
cmp    %ebx,%eax
jge    11b2 <nfschmod+0x62>
lea    0x1(%rax),%ecx
mov    %ecx,0x0(%r13)
cltq
mov    (%r14,%rax,8),%rbp
mov    %rbp,%rdi
mov    %r15d,%esi
call   1040 <chmod@plt>
test   %rax,%rax
jns    1220 <nfschmod+0xd0>
mov    %rbp,%rdi
call   1050 <perror@plt>
jmp    1220 <nfschmod+0xd0>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [16 x i8] c"Invalid option\0A\00"
@optind = global i32 0
@.str.2 = [31 x i8] c"missing mode and/or file name\0A\00"
@.str.3 = [20 x i8] c"bad file mode \22%s\22\0A\00"
define i32 @nfschmod(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %10
10: ; preds = %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 %20
15: ; preds = %10
%16 = load i32, i32* %7
switch i32 %16, label %17 [
]
17: ; preds = %15
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %69
20: ; preds = %10
%21 = load i32, i32* @optind
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 2
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %69
28: ; preds = %20
%29 = load i8**, i8*** %5
%30 = load i32, i32* @optind
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @strtoul(i8* %33, i8** %9, i32 8)
store i32 %34, i32* %6
%35 = load i8*, i8** %9
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %28
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = load i32, i32* @optind
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %44)
store i32 1, i32* %3
br label %69
46: ; preds = %28
%47 = load i32, i32* @optind
%48 = add nsw i32 %47, 1
store i32 %48, i32* @optind
br label %49
49: ; preds = %67, %46
%50 = load i32, i32* @optind
%51 = load i32, i32* %4
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %68
53: ; preds = %49
%54 = load i8**, i8*** %5
%55 = load i32, i32* @optind
%56 = add nsw i32 %55, 1
store i32 %56, i32* @optind
%57 = sext i32 %55 to i64
%58 = getelementptr inbounds i8*, i8** %54, i64 %57
%59 = load i8*, i8** %58
store i8* %59, i8** %8
%60 = load i8*, i8** %8
%61 = load i32, i32* %6
%62 = call i64 @chmod(i8* %60, i32 %61)
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %53
%65 = load i8*, i8** %8
%66 = call i32 @perror(i8* %65)
br label %67
67: ; preds = %64, %53
br label %49
68: ; preds = %49
store i32 0, i32* %3
br label %69
69: ; preds = %68, %38, %25, %17
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [16 x i8] c"Invalid option\0A\00"
@optind = global i32 0
@.str.2 = [31 x i8] c"missing mode and/or file name\0A\00"
@.str.3 = [20 x i8] c"bad file mode \22%s\22\0A\00"
define i32 @nfschmod(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%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 %10, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %49
10: ; preds = %2
%11 = load i32, i32* @optind
%12 = add nsw i32 %0, -2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %49
17: ; preds = %10
%18 = sext i32 %11 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 @strtoul(i8* %20, i8** %3, i32 8)
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = load i32, i32* @optind
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %49
32: ; preds = %17
%33 = load i32, i32* @optind
%34 = add nsw i32 %33, 1
store i32 %34, i32* @optind
%35 = icmp slt i32 %34, %0
br i1 %35, label %36, label %49
36: ; preds = %32, %46
%37 = phi i32 [ %47, %46 ], [ %34, %32 ]
%38 = add nsw i32 %37, 1
store i32 %38, i32* @optind
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8*, i8** %1, i64 %39
%41 = load i8*, i8** %40
%42 = tail call i64 @chmod(i8* %41, i32 %21)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = tail call i32 @perror(i8* %41)
br label %46
46: ; preds = %44, %36
%47 = load i32, i32* @optind
%48 = icmp slt i32 %47, %0
br i1 %48, label %36, label %49
49: ; preds = %46, %32, %25, %14, %7
%50 = phi i32 [ 1, %7 ], [ 1, %14 ], [ 1, %25 ], [ 0, %32 ], [ 0, %46 ]
ret i32 %50
}