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

/* Variables and functions */
int S_IXUSR;
int chmod(char const *, int);
scalar_t__ stat(char const *, struct stat *);
int make_executable(const char *path) {
  int rval = 0;
  struct stat st;

  ;
  if ((!path) || (!*path))
    return 0;
  if (stat(path, &st) >= 0) {
    rval = chmod(path, st.st_mode | 0 | 0 | S_IXUSR);
  }
  return rval;
}


x86 assembly (clang, -O0):
<make_executable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114b <make_executable+0x2b>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1157 <make_executable+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1192 <make_executable+0x72>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jl     118c <make_executable+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
or     $0x0,%esi
or     $0x0,%esi
mov    0x2e66(%rip),%rax
or     (%rax),%esi
call   1040 <chmod@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_executable>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     1158 <make_executable+0x38>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1158 <make_executable+0x38>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <stat@plt>
test   %rax,%rax
js     1158 <make_executable+0x38>
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
or     (%rsp),%esi
mov    %rbx,%rdi
call   1040 <chmod@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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