#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 */

/* Variables and functions */
int /*<<< orphan*/ endnetgrent();
int getnetgrent(char **, char **, char **);
int /*<<< orphan*/ printf(char *, ...);
int setnetgrent(char *);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Usage: test-netgroup <name>\n");
    return -1;
  }
  char *name = argv[1];
  char *host;
  char *user;
  char *domain;
  int found = setnetgrent(name);
  if (!found) {
    printf("Netgroup %s not found.\n", name);
    return -1;
  }
  int more = getnetgrent(&host, &user, &domain);
  while (more > 0) {
    printf("Host   : %s\n", host);
    printf("User   : %s\n", user);
    printf("Domain : %s\n", domain);
    printf("\n");
    more = getnetgrent(&host, &user, &domain);
  }
  endnetgrent();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <main+0x103>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <setnetgrent@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    11ba <main+0x7a>
mov    -0x18(%rbp),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <main+0x103>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <getnetgrent@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    1235 <main+0xf5>
mov    -0x20(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <getnetgrent@plt>
mov    %eax,-0x38(%rbp)
jmp    11ce <main+0x8e>
mov    $0x0,%al
call   1030 <endnetgrent@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1223 <main+0xc3>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1070 <setnetgrent@plt>
test   %eax,%eax
je     1231 <main+0xd1>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1080 <getnetgrent@plt>
test   %eax,%eax
jle    1218 <main+0xb8>
lea    0xe70(%rip),%r14
lea    0xe76(%rip),%r15
lea    0xe7c(%rip),%r12
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%rbx
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rsp),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1080 <getnetgrent@plt>
test   %eax,%eax
jg     11d0 <main+0x70>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <endnetgrent@plt>
jmp    1247 <main+0xe7>
lea    0xe15(%rip),%rdi
call   1040 <puts@plt>
jmp    1242 <main+0xe2>
lea    0xdc8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: test-netgroup <name>\0A\00"
@.str.1 = [24 x i8] c"Netgroup %s not found.\0A\00"
@.str.2 = [13 x i8] c"Host : %s\0A\00"
@.str.3 = [13 x i8] c"User : %s\0A\00"
@.str.4 = [13 x i8] c"Domain : %s\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %43
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = call i32 @setnetgrent(i8* %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %16
%25 = load i8*, i8** %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 -1, i32* %3
br label %43
27: ; preds = %16
%28 = call i32 @getnetgrent(i8** %7, i8** %8, i8** %9)
store i32 %28, i32* %11
br label %29
29: ; preds = %32, %27
%30 = load i32, i32* %11
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %8
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %9
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 @getnetgrent(i8** %7, i8** %8, i8** %9)
store i32 %40, i32* %11
br label %29
41: ; preds = %29
%42 = call i32 (...) @endnetgrent()
store i32 0, i32* %3
br label %43
43: ; preds = %41, %24, %14
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"Netgroup %s not found.\0A\00"
@.str.2 = [13 x i8] c"Host : %s\0A\00"
@.str.3 = [13 x i8] c"User : %s\0A\00"
@.str.4 = [13 x i8] c"Domain : %s\0A\00"
@str = [28 x i8] c"Usage: test-netgroup <name>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = icmp eq i32 %0, 2
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %36
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = bitcast i8** %3 to i8*
%13 = bitcast i8** %4 to i8*
%14 = bitcast i8** %5 to i8*
%15 = tail call i32 @setnetgrent(i8* %11)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %34
19: ; preds = %9
%20 = call i32 @getnetgrent(i8** %3, i8** %4, i8** %5)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %19, %22
%23 = load i8*, i8** %3
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %4
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %5
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = call i32 @putchar(i32 10)
%30 = call i32 @getnetgrent(i8** %3, i8** %4, i8** %5)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %22, label %32
32: ; preds = %22, %19
%33 = call i32 (...) @endnetgrent()
br label %34
34: ; preds = %32, %17
%35 = phi i32 [ 0, %32 ], [ -1, %17 ]
br label %36
36: ; preds = %34, %7
%37 = phi i32 [ -1, %7 ], [ %35, %34 ]
ret i32 %37
}