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

/* Variables and functions */
struct group *getgrgid(int /*<<< orphan*/);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int tty_in_ttygrp(struct stat *st) {
  struct group *gr;
  if ((gr = getgrgid(st->st_gid)) == NULL)
    return 0;
  if (strcmp(gr->gr_name, "tty") != 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<tty_in_ttygrp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1151 <tty_in_ttygrp+0x31>
movl   $0x0,-0x4(%rbp)
jmp    1180 <tty_in_ttygrp+0x60>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1179 <tty_in_ttygrp+0x59>
movl   $0x0,-0x4(%rbp)
jmp    1180 <tty_in_ttygrp+0x60>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_in_ttygrp>:
push   %rax
mov    (%rdi),%edi
call   1030 <getgrgid@plt>
test   %rax,%rax
je     1148 <tty_in_ttygrp+0x28>
mov    (%rax),%edi
lea    0xeca(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.group = type { i32 }
@.str = [4 x i8] c"tty\00"
define i32 @tty_in_ttygrp(%struct.stat* nocapture %0) {
%2 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = tail call %struct.group* @getgrgid(i32 %3)
%5 = icmp eq %struct.group* %4, null
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.group, %struct.group* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @strcmp(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %6, %1
%13 = phi i32 [ 0, %1 ], [ %11, %6 ]
ret i32 %13
}