#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;
};

/* Variables and functions */
int chmod(char *, int /*<<< orphan*/);
struct group *getgrnam(char *);
int /*<<< orphan*/ perror(char *);
int main(void) {
  struct group *gr;
  int ret;
  gr = getgrnam("ss1");
  if (!gr) {
    perror("getgrnam");
    return 1;
  }
  ret = chmod("salo.txt", gr->gr_gid);
  if (ret) {
    perror("chmod");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getgrnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1172 <main+0x42>
lea    0xea3(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    119d <main+0x6d>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
call   1040 <chmod@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     119d <main+0x6d>
lea    0xe7e(%rip),%rdi
call   1050 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1030 <getgrnam@plt>
test   %rax,%rax
je     115a <main+0x2a>
mov    (%rax),%esi
lea    0xec2(%rip),%rdi
call   1040 <chmod@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    1168 <main+0x38>
mov    %ebx,%eax
pop    %rbx
ret
mov    $0x1,%ebx
lea    0xe9e(%rip),%rdi
jmp    116f <main+0x3f>
lea    0xea7(%rip),%rdi
call   1050 <perror@plt>
jmp    1156 <main+0x26>

LLVM IR (-O0):
%struct.group = type { i32 }
@.str = [4 x i8] c"ss1\00"
@.str.1 = [9 x i8] c"getgrnam\00"
@.str.2 = [9 x i8] c"salo.txt\00"
@.str.3 = [6 x i8] c"chmod\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.group*
%3 = alloca i32
store i32 0, i32* %1
%4 = call %struct.group* @getgrnam(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store %struct.group* %4, %struct.group** %2
%5 = load %struct.group*, %struct.group** %2
%6 = icmp ne %struct.group* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %18
9: ; preds = %0
%10 = load %struct.group*, %struct.group** %2
%11 = getelementptr inbounds %struct.group, %struct.group* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @chmod(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %7, %16, %9
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
%struct.group = type { i32 }
@.str = [4 x i8] c"ss1\00"
@.str.1 = [9 x i8] c"getgrnam\00"
@.str.2 = [9 x i8] c"salo.txt\00"
@.str.3 = [6 x i8] c"chmod\00"
define i32 @main() {
%1 = tail call %struct.group* @getgrnam(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq %struct.group* %1, null
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = getelementptr inbounds %struct.group, %struct.group* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = tail call i32 @chmod(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %3, %0
%9 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %3 ]
%10 = phi i32 [ 1, %0 ], [ 0, %3 ]
%11 = tail call i32 @perror(i8* %9)
br label %12
12: ; preds = %8, %3
%13 = phi i32 [ 0, %3 ], [ %10, %8 ]
ret i32 %13
}