#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 */
scalar_t__ EPERM;
scalar_t__ errno;
int /*<<< orphan*/ getegid();
scalar_t__ getenv(char *);
int /*<<< orphan*/ geteuid();
scalar_t__ lchown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  uid_t uid = geteuid();
  gid_t gid = getegid();
  if (argc < 2)
    return 125;
  if (lchown(argv[1], uid, gid) < 0) {
    if (getenv("PANDORA_TEST_SUCCESS")) {
      perror("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/alip/pandora/refs/heads/master/tests/"
             "t005_lchown.c");
      return 1;
    } else if (getenv("PANDORA_TEST_EPERM") && errno == EPERM)
      return 0;
    perror("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/alip/pandora/refs/heads/master/tests/"
           "t005_lchown.c");
    return 1;
  }
  return getenv("PANDORA_TEST_SUCCESS") ? 0 : 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <getegid@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1190 <main+0x40>
movl   $0x7d,-0x4(%rbp)
jmp    1254 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <lchown@plt>
cmp    $0x0,%rax
jge    1234 <main+0xe4>
lea    0xe4c(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11db <main+0x8b>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0x104>
lea    0xec0(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1217 <main+0xc7>
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
mov    0x2dce(%rip),%rcx
cmp    (%rcx),%rax
jne    1217 <main+0xc7>
movl   $0x0,-0x4(%rbp)
jmp    1254 <main+0x104>
jmp    121c <main+0xcc>
lea    0xdf2(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0x104>
lea    0xdc5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdx
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getegid@plt>
mov    %eax,%edx
mov    $0x7d,%eax
cmp    $0x2,%ebx
jl     11d1 <main+0x81>
mov    0x8(%r14),%rdi
mov    %ebp,%esi
call   1050 <lchown@plt>
mov    %rax,%rbx
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
test   %rbx,%rbx
js     11a3 <main+0x53>
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    %eax,%eax
jmp    11d1 <main+0x81>
test   %rcx,%rcx
jne    11d6 <main+0x86>
lea    0xef3(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11d6 <main+0x86>
mov    0x2e20(%rip),%rax
mov    (%rax),%rcx
mov    0x2e06(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
jne    11d6 <main+0x86>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe38(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11d1 <main+0x81>

LLVM IR (-O0):
@.str = [21 x i8] c"PANDORA_TEST_SUCCESS\00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/alip/pandora/refs/heads/master/tests/t005_lchown.c\00"
@.str.2 = [19 x i8] c"PANDORA_TEST_EPERM\00"
@errno = global i64 0
@EPERM = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @geteuid()
store i32 %8, i32* %6
%9 = call i32 (...) @getegid()
store i32 %9, i32* %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 125, i32* %3
br label %42
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = call i64 @lchown(i8* %16, i32 %17, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %13
%22 = call i64 @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %42
26: ; preds = %21
%27 = call i64 @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i64, i64* @errno
%31 = load i64, i64* @EPERM
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 0, i32* %3
br label %42
34: ; preds = %29, %26
br label %35
35: ; preds = %34
%36 = call i32 @perror(i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %42
37: ; preds = %13
%38 = call i64 @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%39 = icmp ne i64 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i32 0, i32 2
store i32 %41, i32* %3
br label %42
42: ; preds = %37, %35, %33, %24, %12
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [21 x i8] c"PANDORA_TEST_SUCCESS\00"
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/alip/pandora/refs/heads/master/tests/t005_lchown.c\00"
@.str.2 = [19 x i8] c"PANDORA_TEST_EPERM\00"
@errno = global i64 0
@EPERM = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @geteuid()
%4 = tail call i32 (...) @getegid()
%5 = icmp slt i32 %0, 2
br i1 %5, label %27, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @lchown(i8* %8, i32 %3, i32 %4)
%10 = icmp slt i64 %9, 0
%11 = tail call i64 @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %10, label %13, label %25
13: ; preds = %6
br i1 %12, label %16, label %14
14: ; preds = %13
%15 = tail call i32 @perror(i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0))
br label %27
16: ; preds = %13
%17 = tail call i64 @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = load i64, i64* @errno
%21 = load i64, i64* @EPERM
%22 = icmp eq i64 %20, %21
br i1 %22, label %27, label %23
23: ; preds = %16, %19
%24 = tail call i32 @perror(i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0))
br label %27
25: ; preds = %6
%26 = select i1 %12, i32 2, i32 0
br label %27
27: ; preds = %19, %2, %25, %23, %14
%28 = phi i32 [ 1, %14 ], [ 1, %23 ], [ %26, %25 ], [ 125, %2 ], [ 0, %19 ]
ret i32 %28
}