#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 */
struct stat {
  int st_mode;
};
typedef int mode_t;

/* Variables and functions */
scalar_t__ S_ISREG(int);
int S_IWOTH;
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    perror("Por favor, introduce solo 1 argumento\n");
    exit(1);
  }
  struct stat datos;
  if ((stat(argv[1], &datos)) < 0) {
    perror("No se pudieron acceder a los datos del archivo\n");
    exit(1);
  }
  if (S_ISREG(datos.st_mode)) {
    if (S_ISREG(datos.st_mode)) {
      mode_t permisosa = datos.st_mode;
      chmod(argv[1], (permisosa | S_IWOTH));
    }
  } else {
    printf("Esta mierda solo rula con archivos regulares \n");
  }
}


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   $0x2,-0x8(%rbp)
jge    1196 <main+0x36>
lea    0xe79(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    11c7 <main+0x67>
lea    0xe6f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     120f <main+0xaf>
mov    -0x18(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     120a <main+0xaa>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2dd5(%rip),%rax
or     (%rax),%esi
call   1060 <chmod@plt>
jmp    121b <main+0xbb>
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jle    11c8 <main+0x68>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
js     11d1 <main+0x71>
mov    0x8(%rsp),%edi
call   1050 <S_ISREG@plt>
test   %rax,%rax
je     11b4 <main+0x54>
mov    0x8(%rsp),%edi
call   1050 <S_ISREG@plt>
test   %rax,%rax
je     11c0 <main+0x60>
mov    0x8(%rbx),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
or     0x8(%rsp),%esi
call   1060 <chmod@plt>
jmp    11c0 <main+0x60>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe31(%rip),%rdi
jmp    11d8 <main+0x78>
lea    0xe4f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [39 x i8] c"Por favor, introduce solo 1 argumento\0A\00"
@.str.1 = [48 x i8] c"No se pudieron acceder a los datos del archivo\0A\00"
@S_IWOTH = global i32 0
@.str.2 = [47 x i8] c"Esta mierda solo rula con archivos regulares \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @stat(i8* %16, %struct.stat* %6)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @S_ISREG(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %43
27: ; preds = %22
%28 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i64 @S_ISREG(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %27
%33 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%34 = load i32, i32* %33
store i32 %34, i32* %7
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i32, i32* %7
%39 = load i32, i32* @S_IWOTH
%40 = or i32 %38, %39
%41 = call i32 @chmod(i8* %37, i32 %40)
br label %42
42: ; preds = %32, %27
br label %45
43: ; preds = %22
%44 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %42
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [39 x i8] c"Por favor, introduce solo 1 argumento\0A\00"
@.str.1 = [48 x i8] c"No se pudieron acceder a los datos del archivo\0A\00"
@S_IWOTH = global i32 0
@str = [46 x i8] c"Esta mierda solo rula con archivos regulares \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = bitcast %struct.stat* %3 to i8*
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @stat(i8* %11, %struct.stat* %3)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @S_ISREG(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %17
%23 = load i32, i32* %18
%24 = call i64 @S_ISREG(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %22
%27 = load i32, i32* %18
%28 = load i8*, i8** %10
%29 = load i32, i32* @S_IWOTH
%30 = or i32 %29, %27
%31 = call i32 @chmod(i8* %28, i32 %30)
br label %34
32: ; preds = %17
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %22, %26, %32
ret i32 0
}