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

/* Variables and functions */
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ dump(struct group *);
int /*<<< orphan*/ endgrent();
struct group *getgrent();
struct group *getgrnam(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setgrent();
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
scan_group() {
  struct group *g;
  signal(SIGPIPE, SIG_IGN);
  setgrent();
  while ((g = getgrent()) != NULL) {
    dump(g);
  }
  endgrent();
  sleep(10);
  printf("==> getgrnam(qmail)\n");
  g = getgrnam("qmail");
  if (g != NULL)
    dump(g);
}


x86 assembly (clang, -O0):
<scan_group>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
mov    $0x0,%al
call   1060 <setgrent@plt>
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11c9 <scan_group+0x49>
mov    -0x10(%rbp),%rdi
call   1070 <dump@plt>
jmp    11a6 <scan_group+0x26>
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    $0xa,%edi
call   10a0 <sleep@plt>
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
call   1090 <getgrnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     120a <scan_group+0x8a>
mov    -0x10(%rbp),%rdi
call   1070 <dump@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_group>:
push   %rax
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
xor    %eax,%eax
call   1060 <setgrent@plt>
nop
xor    %eax,%eax
call   1040 <getgrent@plt>
test   %rax,%rax
je     11b6 <scan_group+0x36>
mov    %rax,%rdi
call   1070 <dump@plt>
jmp    11a0 <scan_group+0x20>
xor    %eax,%eax
call   1030 <endgrent@plt>
mov    $0xa,%edi
call   10a0 <sleep@plt>
lea    0xe38(%rip),%rdi
call   1050 <puts@plt>
lea    0xe26(%rip),%rdi
call   1090 <getgrnam@plt>
test   %rax,%rax
je     11ec <scan_group+0x6c>
mov    %rax,%rdi
call   1070 <dump@plt>
pop    %rcx
ret

LLVM IR (-O0):
%struct.group = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [21 x i8] c"==> getgrnam(qmail)\0A\00"
@.str.1 = [6 x i8] c"qmail\00"
define i32 @scan_group() {
%1 = alloca i32
%2 = alloca %struct.group*
%3 = load i32, i32* @SIGPIPE
%4 = load i32, i32* @SIG_IGN
%5 = call i32 @signal(i32 %3, i32 %4)
%6 = call i32 (...) @setgrent()
br label %7
7: ; preds = %10, %0
%8 = call %struct.group* (...) @getgrent()
store %struct.group* %8, %struct.group** %2
%9 = icmp ne %struct.group* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load %struct.group*, %struct.group** %2
%12 = call i32 @dump(%struct.group* %11)
br label %7
13: ; preds = %7
%14 = call i32 (...) @endgrent()
%15 = call i32 @sleep(i32 10)
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%17 = call %struct.group* @getgrnam(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store %struct.group* %17, %struct.group** %2
%18 = load %struct.group*, %struct.group** %2
%19 = icmp ne %struct.group* %18, null
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load %struct.group*, %struct.group** %2
%22 = call i32 @dump(%struct.group* %21)
br label %23
23: ; preds = %20, %13
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
%struct.group = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str.1 = [6 x i8] c"qmail\00"
@str = [20 x i8] c"==> getgrnam(qmail)\00"
define i32 @scan_group() {
%1 = load i32, i32* @SIGPIPE
%2 = load i32, i32* @SIG_IGN
%3 = tail call i32 @signal(i32 %1, i32 %2)
%4 = tail call i32 (...) @setgrent()
%5 = tail call %struct.group* (...) @getgrent()
%6 = icmp eq %struct.group* %5, null
br i1 %6, label %12, label %7
7: ; preds = %0, %7
%8 = phi %struct.group* [ %10, %7 ], [ %5, %0 ]
%9 = tail call i32 @dump(%struct.group* %8)
%10 = tail call %struct.group* (...) @getgrent()
%11 = icmp eq %struct.group* %10, null
br i1 %11, label %12, label %7
12: ; preds = %7, %0
%13 = tail call i32 (...) @endgrent()
%14 = tail call i32 @sleep(i32 10)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%16 = tail call %struct.group* @getgrnam(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq %struct.group* %16, null
br i1 %17, label %20, label %18
18: ; preds = %12
%19 = tail call i32 @dump(%struct.group* %16)
br label %20
20: ; preds = %18, %12
ret i32 undef
}