#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 mode_t;

/* Variables and functions */
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int chmod(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  mode_t file_mode = (S_IRWXG | S_IRWXU | S_IRWXO);
  if (argc < 2) {
    printf(
        "Usage:\n\tUsing this bin change file mode to 0777\n\t%s <filename>\n",
        argv[0]);
    return 1;
  }
  if (chmod(argv[1], file_mode) == -1) {
    printf("ERR: chmod failed!\n");
    return 1;
  }
  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)
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    0x2e9a(%rip),%rcx
or     (%rcx),%eax
mov    0x2ea1(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117f <main+0x5f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b9 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1040 <chmod@plt>
cmp    $0xffffffff,%eax
jne    11b2 <main+0x92>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b9 <main+0x99>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x1,%edi
jg     1149 <main+0x19>
mov    (%rsi),%rsi
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1186 <main+0x56>
mov    0x2e88(%rip),%rcx
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2e8e(%rip),%rcx
or     (%rcx),%eax
mov    0x8(%rsi),%rdi
mov    %eax,%esi
call   1050 <chmod@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     117a <main+0x4a>
pop    %rcx
ret
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@S_IRWXG = global i32 0
@S_IRWXU = global i32 0
@S_IRWXO = global i32 0
@.str = [64 x i8] c"Usage:\0A\09Using this bin change file mode to 0777\0A\09%s <filename>\0A\00"
@.str.1 = [20 x i8] c"ERR: chmod failed!\0A\00"
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* @S_IRWXG
%8 = load i32, i32* @S_IRWXU
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRWXO
%11 = or i32 %9, %10
store i32 %11, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %29
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* %6
%24 = call i32 @chmod(i8* %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %29
28: ; preds = %19
store i32 0, i32* %3
br label %29
29: ; preds = %28, %26, %14
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@S_IRWXG = global i32 0
@S_IRWXU = global i32 0
@S_IRWXO = global i32 0
@.str = [64 x i8] c"Usage:\0A\09Using this bin change file mode to 0777\0A\09%s <filename>\0A\00"
@str = [19 x i8] c"ERR: chmod failed!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %19
7: ; preds = %2
%8 = load i32, i32* @S_IRWXG
%9 = load i32, i32* @S_IRWXU
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IRWXO
%12 = or i32 %10, %11
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @chmod(i8* %14, i32 %12)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %7
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %7, %17, %4
%20 = phi i32 [ 1, %4 ], [ 1, %17 ], [ 0, %7 ]
ret i32 %20
}