#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_IXGRP;
int S_IXOTH;
int S_IXUSR;
scalar_t__ chmod(char *, int);
scalar_t__ stat(char *, struct stat *);
int make_executable(char *path) {
  struct stat file_stat;
  if (stat(path, &file_stat) ||
      chmod(path, file_stat.st_mode | S_IXOTH | S_IXGRP | S_IXUSR))
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<make_executable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jne    1174 <make_executable+0x54>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    0x2e97(%rip),%rax
or     (%rax),%esi
mov    0x2e7e(%rip),%rax
or     (%rax),%esi
mov    0x2e7d(%rip),%rax
or     (%rax),%esi
call   1040 <chmod@plt>
cmp    $0x0,%rax
je     1180 <make_executable+0x60>
movl   $0x1,-0x4(%rbp)
jmp    1187 <make_executable+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%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    $0x1,%eax
test   %rcx,%rcx
jne    1171 <make_executable+0x51>
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
or     0x8(%rsp),%esi
mov    0x2e85(%rip),%rax
or     (%rax),%esi
mov    0x2e84(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1040 <chmod@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IXOTH = global i32 0
@S_IXGRP = global i32 0
@S_IXUSR = global i32 0
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 %18
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @S_IXOTH
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IXGRP
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IXUSR
%14 = or i32 %12, %13
%15 = call i64 @chmod(i8* %0, i32 %14)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %6, %1
%19 = phi i32 [ 1, %1 ], [ %17, %6 ]
ret i32 %19
}