#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;
struct group {
  int /*<<< orphan*/ gr_gid;
};

/* Variables and functions */
int S_IRGRP;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ chmod(char const *, int);
int /*<<< orphan*/ chown(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
struct group *getgrnam(char const *);
void chgroup(const char *path, const char *group_str) {
  struct group *group;
  group = getgrnam(group_str);
  if (group != NULL) {
    chown(path, (uid_t)-1, group->gr_gid);
  }
  chmod(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
}


x86 assembly (clang, -O0):
<chgroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getgrnam@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116c <chgroup+0x3c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1040 <chown@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    0x2e60(%rip),%rax
or     (%rax),%esi
mov    0x2e47(%rip),%rax
or     (%rax),%esi
mov    0x2e56(%rip),%rax
or     (%rax),%esi
call   1050 <chmod@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chgroup>:
push   %rbx
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <getgrnam@plt>
test   %rax,%rax
je     1150 <chgroup+0x20>
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1040 <chown@plt>
mov    0x2e71(%rip),%rax
mov    0x2e82(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e67(%rip),%rax
or     (%rax),%esi
mov    0x2e76(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <chmod@plt>

LLVM IR (-O0):
%struct.group = type { i32 }
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
define void @chgroup(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.group*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call %struct.group* @getgrnam(i8* %6)
store %struct.group* %7, %struct.group** %5
%8 = load %struct.group*, %struct.group** %5
%9 = icmp ne %struct.group* %8, null
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load %struct.group*, %struct.group** %5
%13 = getelementptr inbounds %struct.group, %struct.group* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @chown(i8* %11, i32 -1, i32 %14)
br label %16
16: ; preds = %10, %2
%17 = load i8*, i8** %3
%18 = load i32, i32* @S_IRUSR
%19 = load i32, i32* @S_IWUSR
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IRGRP
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IWGRP
%24 = or i32 %22, %23
%25 = call i32 @chmod(i8* %17, i32 %24)
ret void
}

LLVM IR (-O2):
%struct.group = type { i32 }
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
define void @chgroup(i8* nocapture %0, i8* %1) {
%3 = tail call %struct.group* @getgrnam(i8* %1)
%4 = icmp eq %struct.group* %3, null
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.group, %struct.group* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @chown(i8* %0, i32 -1, i32 %7)
br label %9
9: ; preds = %5, %2
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %11, %10
%13 = load i32, i32* @S_IRGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IWGRP
%16 = or i32 %14, %15
%17 = tail call i32 @chmod(i8* %0, i32 %16)
ret void
}