#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__ chmod(char const *, int);
scalar_t__ stat(char const *, struct stat *);
int make_executable(const char *path) {
  int ret = -1;
  struct stat st;
  mode_t mode;
  if (stat(path, &st) != 0)
    goto out;
  mode = st.st_mode;
  mode |= (mode & 0444) >> 2;
  if (chmod(path, mode) != 0)
    goto out;
  ret = 0;
out:
  return ret;
}


x86 assembly (clang, -O0):
<make_executable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     114f <make_executable+0x2f>
jmp    1188 <make_executable+0x68>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x124,%eax
sar    $0x2,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <chmod@plt>
cmp    $0x0,%rax
je     1181 <make_executable+0x61>
jmp    1188 <make_executable+0x68>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_executable>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    115a <make_executable+0x3a>
mov    0x8(%rsp),%eax
mov    %eax,%esi
shr    $0x2,%esi
and    $0x49,%esi
or     %eax,%esi
mov    %rbx,%rdi
call   1040 <chmod@plt>
neg    %rax
sbb    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @make_executable(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
%6 = load i8*, i8** %2
%7 = call i64 @stat(i8* %6, %struct.stat* %4)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
br label %24
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%12 = load i32, i32* %11
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = and i32 %13, 292
%15 = ashr i32 %14, 2
%16 = load i32, i32* %5
%17 = or i32 %16, %15
store i32 %17, i32* %5
%18 = load i8*, i8** %2
%19 = load i32, i32* %5
%20 = call i64 @chmod(i8* %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %10
br label %24
23: ; preds = %10
store i32 0, i32* %3
br label %24
24: ; preds = %23, %22, %9
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @make_executable(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = lshr i32 %8, 2
%10 = and i32 %9, 73
%11 = or i32 %10, %8
%12 = call i64 @chmod(i8* %0, i32 %11)
%13 = icmp ne i64 %12, 0
%14 = sext i1 %13 to i32
br label %15
15: ; preds = %6, %1
%16 = phi i32 [ -1, %1 ], [ %14, %6 ]
ret i32 %16
}