#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 */
typedef int uid_t;

/* Variables and functions */
scalar_t__ chmod(char const *, int);
scalar_t__ chown(char const *, int const, int /*<<< orphan*/);
int /*<<< orphan*/ createFile(char const *);
int /*<<< orphan*/ deleteFile(int const, char const *);
int /*<<< orphan*/ err(int, char *, char const *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getegid();
scalar_t__ mkdir(char const *, int);
int main(int argc, char **argv) {
  const char kUser1Dir[] = "/user1dir";
  const char kUser2File[] = "/user1dir/user2file";
  const char kUser2File2[] = "/user1dir/user2file2";
  const uid_t user1 = 6666;
  const uid_t user2 = 6667;
  if (mkdir(kUser1Dir, 0755) != 0) {
    err(1, "mkdir(%s)", kUser1Dir);
    exit(1);
  }
  if (chmod(kUser1Dir, 01777) != 0) {
    err(1, "chmod(%s)", kUser1Dir);
    exit(1);
  }
  createFile(kUser2File);
  createFile(kUser2File2);
  if (chown(kUser1Dir, user1, getegid())) {
    err(1, "chown(%s)", kUser1Dir);
    exit(1);
  }
  if (chown(kUser2File, user2, getegid())) {
    err(1, "chown(%s)", kUser2File);
    exit(1);
  }
  if (chown(kUser2File2, user2, getegid())) {
    err(1, "chown(%s)", kUser2File2);
    exit(1);
  }
  deleteFile(user1, kUser2File);
  deleteFile(user2, kUser2File2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe6a(%rip),%rax
mov    %rax,-0x1a(%rbp)
mov    0xe67(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    0xe84(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe81(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe7f(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe85(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe82(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe80(%rip),%eax
mov    %eax,-0x40(%rbp)
mov    0xe7b(%rip),%al
mov    %al,-0x3c(%rbp)
movl   $0x1a0a,-0x54(%rbp)
movl   $0x1a0b,-0x58(%rbp)
lea    -0x1a(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     1231 <main+0xb1>
lea    -0x1a(%rbp),%rdx
mov    $0x1,%edi
lea    0xde8(%rip),%rsi
call   1060 <err@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x1a(%rbp),%rdi
mov    $0x3ff,%esi
call   1090 <chmod@plt>
cmp    $0x0,%rax
je     1268 <main+0xe8>
lea    -0x1a(%rbp),%rdx
mov    $0x1,%edi
lea    0xdbb(%rip),%rsi
call   1060 <err@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x30(%rbp),%rdi
call   1040 <createFile@plt>
lea    -0x50(%rbp),%rdi
call   1040 <createFile@plt>
lea    -0x1a(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1070 <getegid@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%edx
mov    $0x1a0a,%esi
call   1080 <chown@plt>
cmp    $0x0,%rax
je     12c2 <main+0x142>
lea    -0x1a(%rbp),%rdx
mov    $0x1,%edi
lea    0xd6b(%rip),%rsi
call   1060 <err@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   1070 <getegid@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
mov    $0x1a0b,%esi
call   1080 <chown@plt>
cmp    $0x0,%rax
je     130a <main+0x18a>
lea    -0x30(%rbp),%rdx
mov    $0x1,%edi
lea    0xd23(%rip),%rsi
call   1060 <err@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   1070 <getegid@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%edx
mov    $0x1a0b,%esi
call   1080 <chown@plt>
cmp    $0x0,%rax
je     1352 <main+0x1d2>
lea    -0x50(%rbp),%rdx
mov    $0x1,%edi
lea    0xcdb(%rip),%rsi
call   1060 <err@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x30(%rbp),%rsi
mov    $0x1a0a,%edi
call   1050 <deleteFile@plt>
lea    -0x50(%rbp),%rsi
mov    $0x1a0b,%edi
call   1050 <deleteFile@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
movabs $0x696431726573752f,%rax
31 64 69
mov    %rax,(%rsp)
movw   $0x72,0x8(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x656c69,0x20(%rsp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movabs $0x32656c69663272,%rax
mov    %rax,0x3d(%rsp)
mov    %rsp,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jne    1282 <main+0x102>
mov    %rsp,%rdi
mov    $0x3ff,%esi
call   1090 <chmod@plt>
test   %rax,%rax
jne    128b <main+0x10b>
lea    0x10(%rsp),%rdi
call   1040 <createFile@plt>
lea    0x30(%rsp),%rdi
call   1040 <createFile@plt>
xor    %eax,%eax
call   1070 <getegid@plt>
mov    %rsp,%rdi
mov    $0x1a0a,%esi
mov    %eax,%edx
call   1080 <chown@plt>
test   %rax,%rax
jne    1294 <main+0x114>
xor    %eax,%eax
call   1070 <getegid@plt>
lea    0x10(%rsp),%rdi
mov    $0x1a0b,%esi
mov    %eax,%edx
call   1080 <chown@plt>
test   %rax,%rax
jne    12a0 <main+0x120>
xor    %eax,%eax
call   1070 <getegid@plt>
lea    0x30(%rsp),%rdi
mov    $0x1a0b,%esi
mov    %eax,%edx
call   1080 <chown@plt>
test   %rax,%rax
jne    12ae <main+0x12e>
lea    0x10(%rsp),%rsi
mov    $0x1a0a,%edi
call   1050 <deleteFile@plt>
lea    0x30(%rsp),%rsi
mov    $0x1a0b,%edi
call   1050 <deleteFile@plt>
xor    %eax,%eax
add    $0x48,%rsp
ret
lea    0xd81(%rip),%rsi
jmp    129b <main+0x11b>
lea    0xd82(%rip),%rsi
jmp    129b <main+0x11b>
lea    0xd83(%rip),%rsi
mov    %rsp,%rdx
jmp    12ba <main+0x13a>
lea    0xd77(%rip),%rsi
lea    0x10(%rsp),%rdx
jmp    12ba <main+0x13a>
lea    0xd69(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    $0x1,%edi
call   1060 <err@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.kUser1Dir = [10 x i8] c"/user1dir\00"
@__const.main.kUser2File = [20 x i8] c"/user1dir/user2file\00"
@__const.main.kUser2File2 = [21 x i8] c"/user1dir/user2file2\00"
@.str = [10 x i8] c"mkdir(%s)\00"
@.str.1 = [10 x i8] c"chmod(%s)\00"
@.str.2 = [10 x i8] c"chown(%s)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [10 x i8]
%6 = alloca [20 x i8]
%7 = alloca [21 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = bitcast [10 x i8]* %5 to i8*
%11 = bitcast [20 x i8]* %6 to i8*
%12 = bitcast [21 x i8]* %7 to i8*
store i32 6666, i32* %8
store i32 6667, i32* %9
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%14 = call i64 @mkdir(i8* %13, i32 493)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%18 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%22 = call i64 @chmod(i8* %21, i32 1023)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%26 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%30 = call i32 @createFile(i8* %29)
%31 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 0
%32 = call i32 @createFile(i8* %31)
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%34 = call i32 (...) @getegid()
%35 = call i64 @chown(i8* %33, i32 6666, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %28
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%39 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %28
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%43 = call i32 (...) @getegid()
%44 = call i64 @chown(i8* %42, i32 6667, i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%48 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %41
%51 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 0
%52 = call i32 (...) @getegid()
%53 = call i64 @chown(i8* %51, i32 6667, i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 0
%57 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %50
%60 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%61 = call i32 @deleteFile(i32 6666, i8* %60)
%62 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 0
%63 = call i32 @deleteFile(i32 6667, i8* %62)
ret i32 0
}

LLVM IR (-O2):
@__const.main.kUser1Dir = [10 x i8] c"/user1dir\00"
@__const.main.kUser2File = [20 x i8] c"/user1dir/user2file\00"
@__const.main.kUser2File2 = [21 x i8] c"/user1dir/user2file2\00"
@.str = [10 x i8] c"mkdir(%s)\00"
@.str.1 = [10 x i8] c"chmod(%s)\00"
@.str.2 = [10 x i8] c"chown(%s)\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = alloca [20 x i8]
%5 = alloca [21 x i8]
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 0
%9 = call i64 @mkdir(i8* %6, i32 493)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %6)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i64 @chmod(i8* %6, i32 1023)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %14
%21 = call i32 @createFile(i8* %7)
%22 = call i32 @createFile(i8* %8)
%23 = call i32 (...) @getegid()
%24 = call i64 @chown(i8* %6, i32 6666, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %20
%27 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = call i32 (...) @getegid()
%31 = call i64 @chown(i8* %7, i32 6667, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %29
%37 = call i32 (...) @getegid()
%38 = call i64 @chown(i8* %8, i32 6667, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %36
%44 = call i32 @deleteFile(i32 6666, i8* %7)
%45 = call i32 @deleteFile(i32 6667, i8* %8)
ret i32 0
}