#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISLNK(int /*<<< orphan*/);
int _chgrp_do(int, int /*<<< orphan*/, char *);
int _chgrp_do_recursive_do(int, int /*<<< orphan*/, char *);
int _chgrp_error(char *, int);
scalar_t__ lstat(char *, struct stat *);
int _chgrp_do_recursive(int opts, gid_t gid, char *file) {
  struct stat st;
  if ((lstat(file, &st)) != 0)
    return _chgrp_error(file, 1);
  if (!S_ISDIR(st.st_mode))
    return _chgrp_do(opts, gid, file);
  if (!S_ISLNK(st.st_mode))
    return _chgrp_do_recursive_do(opts, gid, file);
  return 0;
}


x86 assembly (clang, -O0):
<_chgrp_do_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <lstat@plt>
cmp    $0x0,%rax
je     119f <_chgrp_do_recursive+0x3f>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1080 <_chgrp_error@plt>
mov    %eax,-0x4(%rbp)
jmp    11f6 <_chgrp_do_recursive+0x96>
mov    -0x20(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    11c7 <_chgrp_do_recursive+0x67>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <_chgrp_do@plt>
mov    %eax,-0x4(%rbp)
jmp    11f6 <_chgrp_do_recursive+0x96>
mov    -0x20(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%eax
jne    11ef <_chgrp_do_recursive+0x8f>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <_chgrp_do_recursive_do@plt>
mov    %eax,-0x4(%rbp)
jmp    11f6 <_chgrp_do_recursive+0x96>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_chgrp_do_recursive>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rsp,%rsi
mov    %rdx,%rdi
call   1070 <lstat@plt>
test   %rax,%rax
je     1197 <_chgrp_do_recursive+0x37>
mov    %rbx,%rdi
mov    $0x1,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <_chgrp_error@plt>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   1060 <S_ISDIR@plt>
test   %eax,%eax
je     11bd <_chgrp_do_recursive+0x5d>
mov    %ebp,%edi
call   1030 <S_ISLNK@plt>
test   %eax,%eax
je     11d5 <_chgrp_do_recursive+0x75>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <_chgrp_do@plt>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <_chgrp_do_recursive_do@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @_chgrp_do_recursive(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.stat
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = call i64 @lstat(i8* %9, %struct.stat* %8)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = call i32 @_chgrp_error(i8* %13, i32 1)
store i32 %14, i32* %4
br label %36
15: ; preds = %3
%16 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @S_ISDIR(i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = load i8*, i8** %7
%24 = call i32 @_chgrp_do(i32 %21, i32 %22, i8* %23)
store i32 %24, i32* %4
br label %36
25: ; preds = %15
%26 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @S_ISLNK(i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = load i8*, i8** %7
%34 = call i32 @_chgrp_do_recursive_do(i32 %31, i32 %32, i8* %33)
store i32 %34, i32* %4
br label %36
35: ; preds = %25
store i32 0, i32* %4
br label %36
36: ; preds = %35, %30, %20, %12
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @_chgrp_do_recursive(i32 %0, i32 %1, i8* %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i64 @lstat(i8* %2, %struct.stat* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @_chgrp_error(i8* %2, i32 1)
br label %22
10: ; preds = %3
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @S_ISDIR(i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @_chgrp_do(i32 %0, i32 %1, i8* %2)
br label %22
17: ; preds = %10
%18 = tail call i32 @S_ISLNK(i32 %12)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @_chgrp_do_recursive_do(i32 %0, i32 %1, i8* %2)
br label %22
22: ; preds = %17, %20, %15, %8
%23 = phi i32 [ %9, %8 ], [ %21, %20 ], [ %16, %15 ], [ 0, %17 ]
ret i32 %23
}