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

/* Variables and functions */
int /*<<< orphan*/ _chown_id_error(char *, char *, int);
struct group *getgrnam(char *);
scalar_t__ isdigit(int);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
gid_t _chown_gid(char *group) {
  struct group *grp;
  char *p;
  int c;
  if ((grp = getgrnam(group)) != NULL)
    return grp->gr_gid;
  for (p = group; (c = *p) != '\0' && isdigit(c); p++)
    ;
  if (*p != '\0' || *group == '\0')
    return _chown_id_error(group, "group", -1);
  return strtol(group, NULL, 10);
}


x86 assembly (clang, -O0):
<_chown_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getgrnam@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1171 <_chown_gid+0x31>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    121b <_chown_gid+0xdb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
je     11a3 <_chown_gid+0x63>
mov    -0x24(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11b3 <_chown_gid+0x73>
jmp    11c9 <_chown_gid+0x89>
jmp    11b8 <_chown_gid+0x78>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1179 <_chown_gid+0x39>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e9 <_chown_gid+0xa9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1206 <_chown_gid+0xc6>
mov    -0x10(%rbp),%rdi
lea    0xe0c(%rip),%rsi
mov    $0xffffffff,%edx
call   1060 <_chown_id_error@plt>
mov    %eax,-0x4(%rbp)
jmp    121b <_chown_gid+0xdb>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_chown_gid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <getgrnam@plt>
test   %rax,%rax
je     115b <_chown_gid+0x1b>
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%r14),%al
test   %al,%al
je     11ac <_chown_gid+0x6c>
lea    0x1(%r14),%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     118a <_chown_gid+0x4a>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <_chown_gid+0x30>
jmp    1190 <_chown_gid+0x50>
cmpb   $0x0,-0x1(%rbx)
jne    11ac <_chown_gid+0x6c>
cmpb   $0x0,(%r14)
je     11ac <_chown_gid+0x6c>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strtol@plt>
lea    0xe4d(%rip),%rsi
mov    %r14,%rdi
mov    $0xffffffff,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <_chown_id_error@plt>

LLVM IR (-O0):
%struct.group = type { i32 }
@.str = [6 x i8] c"group\00"
define i32 @_chown_gid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.group*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call %struct.group* @getgrnam(i8* %7)
store %struct.group* %8, %struct.group** %4
%9 = icmp ne %struct.group* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load %struct.group*, %struct.group** %4
%12 = getelementptr inbounds %struct.group, %struct.group* %11, i32 0, i32 0
%13 = load i32, i32* %12
store i32 %13, i32* %2
br label %47
14: ; preds = %1
%15 = load i8*, i8** %3
store i8* %15, i8** %5
br label %16
16: ; preds = %28, %14
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
store i32 %19, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* %6
%23 = call i64 @isdigit(i32 %22)
%24 = icmp ne i64 %23, 0
br label %25
25: ; preds = %21, %16
%26 = phi i1 [ false, %16 ], [ %24, %21 ]
br i1 %26, label %27, label %31
27: ; preds = %25
br label %28
28: ; preds = %27
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
br label %16
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %31
%37 = load i8*, i8** %3
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36, %31
%42 = load i8*, i8** %3
%43 = call i32 @_chown_id_error(i8* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 -1)
store i32 %43, i32* %2
br label %47
44: ; preds = %36
%45 = load i8*, i8** %3
%46 = call i32 @strtol(i8* %45, i32* null, i32 10)
store i32 %46, i32* %2
br label %47
47: ; preds = %44, %41, %10
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.group = type { i32 }
@.str = [6 x i8] c"group\00"
define i32 @_chown_gid(i8* %0) {
%2 = tail call %struct.group* @getgrnam(i8* %0)
%3 = icmp eq %struct.group* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %26, label %10
7: ; preds = %1
%8 = getelementptr inbounds %struct.group, %struct.group* %2, i64 0, i32 0
%9 = load i32, i32* %8
br label %30
10: ; preds = %4, %16
%11 = phi i8 [ %18, %16 ], [ %5, %4 ]
%12 = phi i8* [ %17, %16 ], [ %0, %4 ]
%13 = sext i8 %11 to i32
%14 = tail call i64 @isdigit(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %12, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %23, label %10
20: ; preds = %10
%21 = load i8, i8* %12
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16, %20
%24 = load i8, i8* %0
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %4, %23, %20
%27 = tail call i32 @_chown_id_error(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 -1)
br label %30
28: ; preds = %23
%29 = tail call i32 @strtol(i8* nocapture %0, i32* null, i32 10)
br label %30
30: ; preds = %28, %26, %7
%31 = phi i32 [ %9, %7 ], [ %27, %26 ], [ %29, %28 ]
ret i32 %31
}