#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*/ change_mode(char *, int, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ help();
int optind;
int optopt;
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  int opt, is_recursive = 0;
  char *path, *mode_str;
  if (argc <= 1) {
    help();
    return 0;
  }
  while (-1 != (opt = getopt(argc, argv, "Rh"))) {
    switch (opt) {
    case 'R':
      is_recursive = 1;
      break;
    case 'h':
      help();
      return 0;
    default:
      printf("chmod: invalid option -%c\n", optopt);
      help();
      return 0;
    }
  }
  if (optind + 2 != argc) {
    help();
    return 0;
  }
  mode_str = argv[optind];
  path = argv[optind + 1];
  change_mode(path, is_recursive, mode_str);
  return 0;
}


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)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     117a <main+0x3a>
mov    $0x0,%al
call   1060 <help@plt>
movl   $0x0,-0x4(%rbp)
jmp    1285 <main+0x145>
jmp    117f <main+0x3f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe73(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1215 <main+0xd5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x52,%eax
je     11c9 <main+0x89>
jmp    11b8 <main+0x78>
mov    -0x2c(%rbp),%eax
sub    $0x68,%eax
je     11d5 <main+0x95>
jmp    11e8 <main+0xa8>
movl   $0x1,-0x18(%rbp)
jmp    1210 <main+0xd0>
mov    $0x0,%al
call   1060 <help@plt>
movl   $0x0,-0x4(%rbp)
jmp    1285 <main+0x145>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <help@plt>
movl   $0x0,-0x4(%rbp)
jmp    1285 <main+0x145>
jmp    117f <main+0x3f>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
add    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     123d <main+0xfd>
mov    $0x0,%al
call   1060 <help@plt>
movl   $0x0,-0x4(%rbp)
jmp    1285 <main+0x145>
mov    -0x10(%rbp),%rax
mov    0x2d98(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d82(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1040 <change_mode@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11bd <main+0x7d>
mov    %rsi,%r14
mov    %edi,%ebp
xor    %ecx,%ecx
lea    0xea6(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x52,%eax
je     1160 <main+0x20>
cmp    $0xffffffff,%eax
je     119a <main+0x5a>
cmp    $0x68,%eax
je     11bd <main+0x7d>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
jmp    11bd <main+0x7d>
mov    0x2e3f(%rip),%rax
movslq (%rax),%rax
lea    0x2(%rax),%ecx
cmp    %ebp,%ecx
jne    11bd <main+0x7d>
mov    (%r14,%rax,8),%rdx
mov    0x8(%r14,%rax,8),%rdi
mov    %ebx,%esi
call   1040 <change_mode@plt>
jmp    11c4 <main+0x84>
xor    %eax,%eax
call   1060 <help@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"Rh\00"
@.str.1 = [27 x i8] c"chmod: invalid option -%c\0A\00"
@optopt = global i32 0
@optind = 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 i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = load i32, i32* %4
%11 = icmp sle i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @help()
store i32 0, i32* %3
br label %53
14: ; preds = %2
br label %15
15: ; preds = %29, %14
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %6
%19 = icmp ne i32 -1, %18
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = load i32, i32* %6
switch i32 %21, label %25 [
i32 82, label %22
i32 104, label %23
]
22: ; preds = %20
store i32 1, i32* %7
br label %29
23: ; preds = %20
%24 = call i32 (...) @help()
store i32 0, i32* %3
br label %53
25: ; preds = %20
%26 = load i32, i32* @optopt
%27 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = call i32 (...) @help()
store i32 0, i32* %3
br label %53
29: ; preds = %22
br label %15
30: ; preds = %15
%31 = load i32, i32* @optind
%32 = add nsw i32 %31, 2
%33 = load i32, i32* %4
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 (...) @help()
store i32 0, i32* %3
br label %53
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = load i32, i32* @optind
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
store i8* %42, i8** %9
%43 = load i8**, i8*** %5
%44 = load i32, i32* @optind
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %43, i64 %46
%48 = load i8*, i8** %47
store i8* %48, i8** %8
%49 = load i8*, i8** %8
%50 = load i32, i32* %7
%51 = load i8*, i8** %9
%52 = call i32 @change_mode(i8* %49, i32 %50, i8* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %37, %35, %25, %23, %12
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"Rh\00"
@.str.1 = [27 x i8] c"chmod: invalid option -%c\0A\00"
@optopt = global i32 0
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @help()
br label %30
6: ; preds = %2, %6
%7 = phi i32 [ 1, %6 ], [ 0, %2 ]
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %11 [
i32 -1, label %15
i32 82, label %6
i32 104, label %9
]
9: ; preds = %6
%10 = tail call i32 (...) @help()
br label %30
11: ; preds = %6
%12 = load i32, i32* @optopt
%13 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 (...) @help()
br label %30
15: ; preds = %6
%16 = load i32, i32* @optind
%17 = add nsw i32 %16, 2
%18 = icmp eq i32 %17, %0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 (...) @help()
br label %30
21: ; preds = %15
%22 = sext i32 %16 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = add nsw i32 %16, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i32 @change_mode(i8* %28, i32 %7, i8* %24)
br label %30
30: ; preds = %21, %19, %11, %9, %4
ret i32 0
}