#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*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int parse(char **, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage:%s mode filename\n", argv[0]);
    return -1;
  }
  int mode = parse(argv, argc);
  if (chmod(argv[2], mode) < 0) {
    perror("chmod");
    exit(errno);
  }
  return 0;
}


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)
cmpl   $0x3,-0x8(%rbp)
je     118f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <main+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <parse@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1040 <chmod@plt>
cmp    $0x0,%rax
jge    11d2 <main+0x82>
lea    0xe59(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    117d <main+0x2d>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1060 <parse@plt>
mov    0x10(%rbx),%rdi
mov    %eax,%esi
call   1040 <chmod@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1193 <main+0x43>
pop    %rbx
ret
mov    (%rbx),%rsi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
lea    0xe7e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Usage:%s mode filename\0A\00"
@.str.1 = [6 x i8] c"chmod\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 -1, i32* %3
br label %29
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = load i32, i32* %4
%17 = call i32 @parse(i8** %15, i32 %16)
store i32 %17, i32* %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = load i32, i32* %6
%22 = call i64 @chmod(i8* %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %14
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @errno
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %14
store i32 0, i32* %3
br label %29
29: ; preds = %28, %9
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [24 x i8] c"Usage:%s mode filename\0A\00"
@.str.1 = [6 x i8] c"chmod\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %17
7: ; preds = %2
%8 = tail call i32 @parse(i8** %1, i32 3)
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i64 @chmod(i8* %10, i32 %8)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @errno
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %7, %4
%18 = phi i32 [ -1, %4 ], [ 0, %7 ]
ret i32 %18
}