#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;
typedef int gid_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int handle_zng(int);
int lchown(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int lchown_test(char *path, uid_t owner, gid_t group) {
  int ret, save_errno;
  int passed;
  printf("lchown(): path=%s, owner=%u, group=%u\n",
         (((path) == NULL) ? "(null)" : (path)), owner, group);
  fflush(NULL);
  passed = handle_zng(ret = lchown(path, owner, group));
  save_errno = errno;
  switch (passed) {
  case -1:
  case 0:
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = %d\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<lchown_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116d <lchown_test+0x2d>
lea    0xec3(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1175 <lchown_test+0x35>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x30(%rbp)
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <lchown@plt>
mov    %eax,%edi
mov    %edi,-0x14(%rbp)
call   1030 <handle_zng@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xfffffffe,%eax
je     1217 <lchown_test+0xd7>
jmp    11d6 <lchown_test+0x96>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
ja     1236 <lchown_test+0xf6>
jmp    11ea <lchown_test+0xaa>
mov    -0x14(%rbp),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1250 <lchown_test+0x110>
mov    -0x14(%rbp),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1250 <lchown_test+0x110>
mov    -0x1c(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x18(%rbp),%ecx
mov    0x2d86(%rip),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lchown_test>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0xec1(%rip),%rsi
cmovne %rdi,%rsi
lea    0xe8f(%rip),%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1070 <lchown@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <handle_zng@plt>
mov    0x2e3f(%rip),%r14
mov    (%r14),%ebp
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jae    11ca <lchown_test+0x7a>
lea    0xe7b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
jmp    11ea <lchown_test+0x9a>
cmp    $0xfffffffe,%eax
jne    11da <lchown_test+0x8a>
lea    0xe64(%rip),%rdi
mov    %ebx,%esi
jmp    11e3 <lchown_test+0x93>
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %ebp,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"lchown(): path=%s, owner=%u, group=%u\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.3 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @lchown_test(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
br label %15
13: ; preds = %3
%14 = load i8*, i8** %4
br label %15
15: ; preds = %13, %12
%16 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %12 ], [ %14, %13 ]
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17, i32 %18)
%20 = call i32 @fflush(i32* null)
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = call i32 @lchown(i8* %21, i32 %22, i32 %23)
store i32 %24, i32* %7
%25 = call i32 @handle_zng(i32 %24)
store i32 %25, i32* %9
%26 = load i32, i32* @errno
store i32 %26, i32* %8
%27 = load i32, i32* %9
switch i32 %27, label %37 [
i32 -1, label %28
i32 0, label %28
i32 -2, label %33
]
28: ; preds = %15, %15
%29 = load i32, i32* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @fflush(i32* null)
br label %41
33: ; preds = %15
%34 = load i32, i32* %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = call i32 @fflush(i32* null)
br label %41
37: ; preds = %15
%38 = load i32, i32* %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %38)
%40 = call i32 @fflush(i32* null)
br label %41
41: ; preds = %37, %33, %28
%42 = load i32, i32* %8
store i32 %42, i32* @errno
%43 = load i32, i32* %7
ret i32 %43
}

LLVM IR (-O2):
@.str = [39 x i8] c"lchown(): path=%s, owner=%u, group=%u\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @lchown_test(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i8* %0, null
%5 = select i1 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %1, i32 %2)
%7 = tail call i32 @fflush(i32* null)
%8 = tail call i32 @lchown(i8* %0, i32 %1, i32 %2)
%9 = tail call i32 @handle_zng(i32 %8)
%10 = load i32, i32* @errno
switch i32 %9, label %16 [
i32 -1, label %11
i32 0, label %11
i32 -2, label %14
]
11: ; preds = %3, %3
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %18
14: ; preds = %3
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %8)
br label %18
16: ; preds = %3
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %9)
br label %18
18: ; preds = %16, %14, %11
%19 = tail call i32 @fflush(i32* null)
store i32 %10, i32* @errno
ret i32 %8
}