#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ chmod(char *, scalar_t__);
int chown(char *, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strtol(char *, int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  int userUid = atoi(argv[2]);
  if (userUid < 600) {
    fprintf(stderr, "File owner not valid ldap user!\n");
    exit(EXIT_FAILURE);
  }
  struct stat cur_file;
  if (stat(argv[1], &cur_file) == -1) {
    perror("stat");
    exit(EXIT_FAILURE);
  }
  int res = chown(argv[1], userUid, 300);
  if (res == -1) {
    perror("chown");
    exit(EXIT_FAILURE);
  } else {
    if (S_ISDIR(cur_file.st_mode)) {
      chmod(argv[1], (511 - strtol(argv[3], 0, 8)));
    } else {
      chmod(argv[1], (439 - strtol(argv[3], 0, 8)));
    }
  }
  exit(EXIT_SUCCESS);
}


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    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x258,-0x14(%rbp)
jge    11e6 <main+0x56>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    121a <main+0x8a>
lea    0xe1a(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    $0x12c,%edx
call   1070 <chown@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1256 <main+0xc6>
lea    0xde3(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     129e <main+0x10e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <strtol@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1ff,%esi
sub    %rax,%rsi
call   1080 <chmod@plt>
jmp    12cf <main+0x13f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <strtol@plt>
mov    -0x30(%rbp),%rdi
mov    $0x1b7,%esi
sub    %rax,%rsi
call   1080 <chmod@plt>
jmp    12d4 <main+0x144>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   10a0 <atoi@plt>
cmp    $0x257,%eax
jg     11c2 <main+0x32>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1201 <main+0x71>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x50>
lea    0xe43(%rip),%rdi
jmp    11fc <main+0x6c>
mov    0x8(%rbx),%rdi
mov    %ebp,%esi
mov    $0x12c,%edx
call   1070 <chown@plt>
cmp    $0xffffffff,%eax
jne    120f <main+0x7f>
lea    0xe2a(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rbp
mov    0x8(%rbx),%r14
mov    0x18(%rbx),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <strtol@plt>
test   %rbp,%rbp
mov    $0x1b7,%ecx
mov    $0x1ff,%esi
cmove  %rcx,%rsi
sub    %rax,%rsi
mov    %r14,%rdi
call   1080 <chmod@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"File owner not valid ldap user!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"stat\00"
@.str.2 = [6 x i8] c"chown\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 2
%11 = load i8*, i8** %10
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 600
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @stat(i8* %23, %struct.stat* %7)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %20
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i32, i32* %6
%35 = call i32 @chown(i8* %33, i32 %34, i32 300)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %30
%39 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %30
%43 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i64 @S_ISDIR(i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %57
47: ; preds = %42
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 3
%53 = load i8*, i8** %52
%54 = call i64 @strtol(i8* %53, i32 0, i32 8)
%55 = sub nsw i64 511, %54
%56 = call i32 @chmod(i8* %50, i64 %55)
br label %67
57: ; preds = %42
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 3
%63 = load i8*, i8** %62
%64 = call i64 @strtol(i8* %63, i32 0, i32 8)
%65 = sub nsw i64 439, %64
%66 = call i32 @chmod(i8* %60, i64 %65)
br label %67
67: ; preds = %57, %47
br label %68
68: ; preds = %67
%69 = load i32, i32* @EXIT_SUCCESS
%70 = call i32 @exit(i32 %69)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"File owner not valid ldap user!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"stat\00"
@.str.2 = [6 x i8] c"chown\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = getelementptr inbounds i8*, i8** %1, i64 2
%5 = load i8*, i8** %4
%6 = tail call i32 @atoi(i8* %5)
%7 = icmp slt i32 %6, 600
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = bitcast %struct.stat* %3 to i8*
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @stat(i8* %16, %struct.stat* %3)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
%24 = load i8*, i8** %15
%25 = tail call i32 @chown(i8* %24, i32 %6, i32 300)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
%32 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%33 = load i32, i32* %32
%34 = tail call i64 @S_ISDIR(i32 %33)
%35 = icmp eq i64 %34, 0
%36 = load i8*, i8** %15
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = load i8*, i8** %37
%39 = tail call i64 @strtol(i8* %38, i32 0, i32 8)
%40 = select i1 %35, i64 439, i64 511
%41 = sub nsw i64 %40, %39
%42 = tail call i32 @chmod(i8* %36, i64 %41)
%43 = load i32, i32* @EXIT_SUCCESS
%44 = tail call i32 @exit(i32 %43)
unreachable
}