#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;
scalar_t__ ft_memalloc(int);
int /*<<< orphan*/ ft_memdel(void **);
scalar_t__ lstat(char *, struct stat *);
int test_rights(char *file) {
  struct stat *buf;
  int i;
  if (!(buf = (struct stat *)ft_memalloc(sizeof(struct stat))))
    return (-1);
  i = 0;
  if (lstat(file, buf) < 0)
    return (-1);
  if (buf->st_mode & S_IXUSR)
    i = 1;
  ft_memdel((void **)&buf);
  return (i);
}


x86 assembly (clang, -O0):
<test_rights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x4,%edi
call   1050 <ft_memalloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1160 <test_rights+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <test_rights+0x88>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
jge    118a <test_rights+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <test_rights+0x88>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2e51(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11a9 <test_rights+0x79>
movl   $0x1,-0x1c(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <ft_memdel@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rights>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    $0x4,%edi
call   1050 <ft_memalloc@plt>
mov    %rax,0x8(%rsp)
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1182 <test_rights+0x52>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <lstat@plt>
test   %rax,%rax
js     1182 <test_rights+0x52>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
xor    %ebp,%ebp
and    (%rbx),%eax
setne  %bpl
lea    0x8(%rsp),%rdi
call   1030 <ft_memdel@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IXUSR = global i32 0
define i32 @test_rights(i8* nocapture %0) {
%2 = alloca %struct.stat*
%3 = bitcast %struct.stat** %2 to i8*
%4 = tail call i64 @ft_memalloc(i32 4)
%5 = inttoptr i64 %4 to %struct.stat*
store %struct.stat* %5, %struct.stat** %2
%6 = icmp eq i64 %4, 0
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = tail call i64 @lstat(i8* %0, %struct.stat* %5)
%9 = icmp slt i64 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IXUSR
%14 = and i32 %13, %12
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i32
%17 = bitcast %struct.stat** %2 to i8**
%18 = call i32 @ft_memdel(i8** %17)
br label %19
19: ; preds = %7, %1, %10
%20 = phi i32 [ %16, %10 ], [ -1, %1 ], [ -1, %7 ]
ret i32 %20
}