#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 */
int S_IRUSR;
int S_IXUSR;
int /*<<< orphan*/ chmod(char const *, int);
int /*<<< orphan*/ stat(char const *, struct stat *);
void set_file_perm() {
  struct stat st;
  mode_t mode;
  const char *path = "test.txt";
  stat(path, &st);
  mode = st.st_mode & 07777;
  mode &= ~(S_IRUSR);
  mode |= S_IXUSR;
  chmod(path, mode);
}


x86 assembly (clang, -O0):
<set_file_perm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    -0x8(%rbp),%eax
and    $0xfff,%eax
mov    %eax,-0xc(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <chmod@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_file_perm>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <stat@plt>
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
not    %esi
and    0x8(%rsp),%esi
and    $0xfff,%esi
mov    0x2e93(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <chmod@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"test.txt\00"
@S_IRUSR = global i32 0
@S_IXUSR = global i32 0
define void @set_file_perm() {
%1 = alloca %struct.stat
%2 = alloca i32
%3 = alloca i8*
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @stat(i8* %4, %struct.stat* %1)
%6 = getelementptr inbounds %struct.stat, %struct.stat* %1, i32 0, i32 0
%7 = load i32, i32* %6
%8 = and i32 %7, 4095
store i32 %8, i32* %2
%9 = load i32, i32* @S_IRUSR
%10 = xor i32 %9, -1
%11 = load i32, i32* %2
%12 = and i32 %11, %10
store i32 %12, i32* %2
%13 = load i32, i32* @S_IXUSR
%14 = load i32, i32* %2
%15 = or i32 %14, %13
store i32 %15, i32* %2
%16 = load i8*, i8** %3
%17 = load i32, i32* %2
%18 = call i32 @chmod(i8* %16, i32 %17)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"test.txt\00"
@S_IRUSR = global i32 0
@S_IXUSR = global i32 0
define void @set_file_perm() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = and i32 %5, 4095
%7 = load i32, i32* @S_IRUSR
%8 = xor i32 %7, -1
%9 = and i32 %6, %8
%10 = load i32, i32* @S_IXUSR
%11 = or i32 %9, %10
%12 = tail call i32 @chmod(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
ret void
}