#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*/ printf(char *, ...);
int mudapermissao(int argc, char **argv, int permissao) {
  if (argc < 1) {
    if (permissao == 0000)
      printf("Modo de uso: protegepracaramba <arquivo>\n");
    else if (permissao == 0777)
      printf("Modo de uso: liberageral <arquivo>\n");
  }
  if (chmod(argv[0], permissao) == 0) {
    return 0;
  } else {
    printf("Não foi possível mudar as permissões do arquivo %s", argv[1]);
    return -1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<mudapermissao>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    117e <mudapermissao+0x5e>
cmpl   $0x0,-0x14(%rbp)
jne    1159 <mudapermissao+0x39>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1179 <mudapermissao+0x59>
cmpl   $0x1ff,-0x14(%rbp)
jne    1174 <mudapermissao+0x54>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1179 <mudapermissao+0x59>
jmp    117e <mudapermissao+0x5e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
call   1040 <chmod@plt>
cmp    $0x0,%rax
jne    11a3 <mudapermissao+0x83>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <mudapermissao+0xa0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mudapermissao>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
test   %edi,%edi
jg     115d <mudapermissao+0x2d>
test   %ebp,%ebp
je     1151 <mudapermissao+0x21>
cmp    $0x1ff,%ebp
jne    115d <mudapermissao+0x2d>
lea    0xee7(%rip),%rdi
jmp    1158 <mudapermissao+0x28>
lea    0xf01(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
mov    %ebp,%esi
call   1050 <chmod@plt>
test   %rax,%rax
je     1185 <mudapermissao+0x55>
mov    0x8(%rbx),%rsi
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    1187 <mudapermissao+0x57>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Modo de uso: protegepracaramba <arquivo>\0A\00"
@.str.1 = [36 x i8] c"Modo de uso: liberageral <arquivo>\0A\00"
@.str.2 = [54 x i8] c"N\C3\A3o foi poss\C3\ADvel mudar as permiss\C3\B5es do arquivo %s\00"
define i32 @mudapermissao(i32 %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %22
10: ; preds = %3
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %21
15: ; preds = %10
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 511
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
br label %21
21: ; preds = %20, %13
br label %22
22: ; preds = %21, %3
%23 = load i8**, i8*** %6
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = load i32, i32* %7
%27 = call i64 @chmod(i8* %25, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 0, i32* %4
br label %35
30: ; preds = %22
%31 = load i8**, i8*** %6
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* %33)
store i32 -1, i32* %4
br label %35
35: ; preds = %30, %29
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@.str.2 = [54 x i8] c"N\C3\A3o foi poss\C3\ADvel mudar as permiss\C3\B5es do arquivo %s\00"
@str = [35 x i8] c"Modo de uso: liberageral <arquivo>\00"
@str.3 = [41 x i8] c"Modo de uso: protegepracaramba <arquivo>\00"
define i32 @mudapermissao(i32 %0, i8** nocapture %1, i32 %2) {
%4 = icmp slt i32 %0, 1
br i1 %4, label %5, label %10
5: ; preds = %3
switch i32 %2, label %10 [
i32 0, label %7
i32 511, label %6
]
6: ; preds = %5
br label %7
7: ; preds = %5, %6
%8 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @str.3, i64 0, i64 0), %5 ]
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
br label %10
10: ; preds = %7, %5, %3
%11 = load i8*, i8** %1
%12 = tail call i64 @chmod(i8* %11, i32 %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %10, %14
%19 = phi i32 [ -1, %14 ], [ 0, %10 ]
ret i32 %19
}