#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 /*<<< orphan*/ chmod(char const *, int);
int /*<<< orphan*/ execpermfix(char const *, int /*<<< orphan*/,
                               int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, int, int, int);
int /*<<< orphan*/ stat(char const *, struct stat *);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  const char *filename;
  mode_t pre;
  mode_t pos;
  struct stat st;
  (void)argc;
  filename = argv[1];
  pre = strtol(argv[2], NULL, 0);
  pos = strtol(argv[3], NULL, 0);
  chmod(filename, pre);
  execpermfix(filename, 0, 0);
  stat(filename, &st);
  printf("filename %s, pre 0%o, pos 0%o, curr 0%o\n", filename, pre, pos,
         0777 & st.st_mode);
  return pos == (0777 & st.st_mode) ? 0 : 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <chmod@plt>
mov    -0x18(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <execpermfix@plt>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8d
and    $0x1ff,%r8d
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%edx
mov    -0x28(%rbp),%esi
and    $0x1ff,%esi
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%r14d
mov    0x18(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <chmod@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <execpermfix@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
mov    $0x1ff,%ebp
and    (%rsp),%ebp
lea    0xe51(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
call   1030 <printf@plt>
xor    %eax,%eax
cmp    %ebp,%r15d
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [41 x i8] c"filename %s, pre 0%o, pos 0%o, curr 0%o\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @strtol(i8* %16, i32* null, i32 0)
store i32 %17, i32* %7
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 3
%20 = load i8*, i8** %19
%21 = call i32 @strtol(i8* %20, i32* null, i32 0)
store i32 %21, i32* %8
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = call i32 @chmod(i8* %22, i32 %23)
%25 = load i8*, i8** %6
%26 = call i32 @execpermfix(i8* %25, i32 0, i32 0)
%27 = load i8*, i8** %6
%28 = call i32 @stat(i8* %27, %struct.stat* %9)
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 511, %33
%35 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %30, i32 %31, i32 %34)
%36 = load i32, i32* %8
%37 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%38 = load i32, i32* %37
%39 = and i32 511, %38
%40 = icmp eq i32 %36, %39
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 0, i32 1
ret i32 %42
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [41 x i8] c"filename %s, pre 0%o, pos 0%o, curr 0%o\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 @strtol(i8* nocapture %8, i32* null, i32 0)
%10 = getelementptr inbounds i8*, i8** %1, i64 3
%11 = load i8*, i8** %10
%12 = tail call i32 @strtol(i8* nocapture %11, i32* null, i32 0)
%13 = tail call i32 @chmod(i8* %6, i32 %9)
%14 = tail call i32 @execpermfix(i8* %6, i32 0, i32 0)
%15 = call i32 @stat(i8* %6, %struct.stat* %3)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, 511
%19 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %6, i32 %9, i32 %12, i32 %18)
%20 = icmp ne i32 %12, %18
%21 = zext i1 %20 to i32
ret i32 %21
}