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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ chdir(char *);
scalar_t__ chown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ getegid();
int /*<<< orphan*/ geteuid();
int main(int argc, char **argv) {
  char *long_dir, *fname;
  if (3 > argc)
    return EXIT_FAILURE;
  else {
    long_dir = argv[1];
    fname = argv[2];
  }
  for (int i = 0; i < 64; i++) {
    if (0 > chdir(long_dir))
      return EXIT_FAILURE;
  }
  uid_t uid = geteuid();
  gid_t gid = getegid();
  if (0 > chown(fname, uid, gid))
    return EXIT_FAILURE;
  else
    return 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    $0x3,%eax
cmp    -0x8(%rbp),%eax
jle    1175 <main+0x35>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <main+0xe7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x40,-0x24(%rbp)
jge    11d9 <main+0x99>
mov    -0x18(%rbp),%rdi
call   1030 <chdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    11c6 <main+0x86>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <main+0xe7>
jmp    11cb <main+0x8b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1194 <main+0x54>
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <getegid@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1060 <chown@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    121b <main+0xdb>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <main+0xe7>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jle    1193 <main+0x53>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r14
mov    $0x40,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <chdir@plt>
test   %rax,%rax
js     1193 <main+0x53>
add    $0xffffffff,%ebp
jne    1160 <main+0x20>
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getegid@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1060 <chown@plt>
test   %rax,%rax
jns    11a1 <main+0x61>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e30(%rip),%rax
jmp    119a <main+0x5a>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sgt i32 3, %11
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %48
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
store i8* %21, i8** %7
br label %22
22: ; preds = %15
store i32 0, i32* %8
br label %23
23: ; preds = %33, %22
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 64
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = call i64 @chdir(i8* %27)
%29 = icmp sgt i64 0, %28
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %3
br label %48
32: ; preds = %26
br label %33
33: ; preds = %32
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %23
36: ; preds = %23
%37 = call i32 (...) @geteuid()
store i32 %37, i32* %9
%38 = call i32 (...) @getegid()
store i32 %38, i32* %10
%39 = load i8*, i8** %7
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = call i64 @chown(i8* %39, i32 %40, i32 %41)
%43 = icmp sgt i64 0, %42
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = load i32, i32* @EXIT_FAILURE
store i32 %45, i32* %3
br label %48
46: ; preds = %36
%47 = load i32, i32* @EXIT_SUCCESS
store i32 %47, i32* %3
br label %48
48: ; preds = %46, %44, %30, %13
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i32, i32* @EXIT_FAILURE
br label %28
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
br label %14
11: ; preds = %14
%12 = add nuw nsw i32 %15, 1
%13 = icmp eq i32 %12, 64
br i1 %13, label %20, label %14
14: ; preds = %6, %11
%15 = phi i32 [ 0, %6 ], [ %12, %11 ]
%16 = tail call i64 @chdir(i8* %8)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %11
18: ; preds = %14
%19 = load i32, i32* @EXIT_FAILURE
br label %28
20: ; preds = %11
%21 = tail call i32 (...) @geteuid()
%22 = tail call i32 (...) @getegid()
%23 = tail call i64 @chown(i8* %10, i32 %21, i32 %22)
%24 = icmp slt i64 %23, 0
%25 = load i32, i32* @EXIT_FAILURE
%26 = load i32, i32* @EXIT_SUCCESS
%27 = select i1 %24, i32 %25, i32 %26
br label %28
28: ; preds = %18, %20, %4
%29 = phi i32 [ %5, %4 ], [ %27, %20 ], [ %19, %18 ]
ret i32 %29
}