#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*/ gid_t;

/* Variables and functions */
int _chgrp_error(char *, int);
int chown(char *, int, int /*<<< orphan*/);
int lchown(char *, int, int /*<<< orphan*/);
int _chgrp_do(int opts, gid_t gid, char *file) {
  int res;
  if ((opts & 0x1) == 0x1)
    res = lchown(file, -1, gid);
  else
    res = chown(file, -1, gid);
  if (res != 0)
    return _chgrp_error(file, 1);
  return 0;
}


x86 assembly (clang, -O0):
<_chgrp_do>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    116a <_chgrp_do+0x3a>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0xffffffff,%esi
call   1040 <lchown@plt>
mov    %eax,-0x1c(%rbp)
jmp    117e <_chgrp_do+0x4e>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0xffffffff,%esi
call   1050 <chown@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     119e <_chgrp_do+0x6e>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1030 <_chgrp_error@plt>
mov    %eax,-0x4(%rbp)
jmp    11a5 <_chgrp_do+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_chgrp_do>:
push   %rbx
mov    %rdx,%rbx
mov    %esi,%edx
test   $0x1,%dil
jne    115b <_chgrp_do+0x2b>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1050 <chown@plt>
test   %eax,%eax
je     116c <_chgrp_do+0x3c>
mov    %rbx,%rdi
mov    $0x1,%esi
pop    %rbx
jmp    1030 <_chgrp_error@plt>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1040 <lchown@plt>
test   %eax,%eax
jne    114d <_chgrp_do+0x1d>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @_chgrp_do(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i32, i32* %5
%10 = and i32 %9, 1
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = load i32, i32* %6
%15 = call i32 @lchown(i8* %13, i32 -1, i32 %14)
store i32 %15, i32* %8
br label %20
16: ; preds = %3
%17 = load i8*, i8** %7
%18 = load i32, i32* %6
%19 = call i32 @chown(i8* %17, i32 -1, i32 %18)
store i32 %19, i32* %8
br label %20
20: ; preds = %16, %12
%21 = load i32, i32* %8
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i8*, i8** %7
%25 = call i32 @_chgrp_error(i8* %24, i32 1)
store i32 %25, i32* %4
br label %27
26: ; preds = %20
store i32 0, i32* %4
br label %27
27: ; preds = %26, %23
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
define i32 @_chgrp_do(i32 %0, i32 %1, i8* %2) {
%4 = and i32 %0, 1
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @lchown(i8* %2, i32 -1, i32 %1)
br label %10
8: ; preds = %3
%9 = tail call i32 @chown(i8* %2, i32 -1, i32 %1)
br label %10
10: ; preds = %8, %6
%11 = phi i32 [ %7, %6 ], [ %9, %8 ]
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @_chgrp_error(i8* %2, i32 1)
br label %15
15: ; preds = %10, %13
%16 = phi i32 [ %14, %13 ], [ 0, %10 ]
ret i32 %16
}