#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 spwd {
  int /*<<< orphan*/ sp_namp;
};

/* Variables and functions */
int /*<<< orphan*/ endspent();
int /*<<< orphan*/ getspent_r(struct spwd *, char *, size_t, struct spwd **);
int /*<<< orphan*/ strcmp(char const *, int /*<<< orphan*/);
int getspnam_r(const char *name, struct spwd *res, char *buf, size_t buflen,
               struct spwd **res_sig) {
  while (!getspent_r(res, buf, buflen, res_sig))
    if (!strcmp(name, res->sp_namp))
      goto ok;
  *res_sig = 0;
ok:
  endspent();
  return *res_sig ? 0 : -1;
}


x86 assembly (clang, -O0):
<getspnam_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <getspent_r@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1176 <getspnam_r+0x46>
jmp    1198 <getspnam_r+0x68>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1193 <getspnam_r+0x63>
jmp    11a3 <getspnam_r+0x73>
jmp    114c <getspnam_r+0x1c>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    $0x0,%al
call   1030 <endspent@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getspnam_r>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <getspent_r@plt>
test   %eax,%eax
jne    1175 <getspnam_r+0x45>
mov    (%rbx),%esi
mov    %r13,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    1150 <getspnam_r+0x20>
jmp    117c <getspnam_r+0x4c>
movq   $0x0,(%r14)
xor    %eax,%eax
call   1030 <endspent@plt>
cmpq   $0x1,(%r14)
sbb    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.spwd = type { i32 }
define i32 @getspnam_r(i8* %0, %struct.spwd* %1, i8* %2, i64 %3, %struct.spwd** %4) {
%6 = alloca i8*
%7 = alloca %struct.spwd*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.spwd**
store i8* %0, i8** %6
store %struct.spwd* %1, %struct.spwd** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store %struct.spwd** %4, %struct.spwd*** %10
br label %11
11: ; preds = %27, %5
%12 = load %struct.spwd*, %struct.spwd** %7
%13 = load i8*, i8** %8
%14 = load i64, i64* %9
%15 = load %struct.spwd**, %struct.spwd*** %10
%16 = call i32 @getspent_r(%struct.spwd* %12, i8* %13, i64 %14, %struct.spwd** %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %28
19: ; preds = %11
%20 = load i8*, i8** %6
%21 = load %struct.spwd*, %struct.spwd** %7
%22 = getelementptr inbounds %struct.spwd, %struct.spwd* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @strcmp(i8* %20, i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %19
br label %30
27: ; preds = %19
br label %11
28: ; preds = %11
%29 = load %struct.spwd**, %struct.spwd*** %10
store %struct.spwd* null, %struct.spwd** %29
br label %30
30: ; preds = %28, %26
%31 = call i32 (...) @endspent()
%32 = load %struct.spwd**, %struct.spwd*** %10
%33 = load %struct.spwd*, %struct.spwd** %32
%34 = icmp ne %struct.spwd* %33, null
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 0, i32 -1
ret i32 %36
}

LLVM IR (-O2):
%struct.spwd = type { i32 }
define i32 @getspnam_r(i8* %0, %struct.spwd* %1, i8* %2, i64 %3, %struct.spwd** %4) {
%6 = getelementptr inbounds %struct.spwd, %struct.spwd* %1, i64 0, i32 0
br label %7
7: ; preds = %10, %5
%8 = tail call i32 @getspent_r(%struct.spwd* %1, i8* %2, i64 %3, %struct.spwd** %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* %6
%12 = tail call i32 @strcmp(i8* %0, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %15, label %7
14: ; preds = %7
store %struct.spwd* null, %struct.spwd** %4
br label %15
15: ; preds = %10, %14
%16 = tail call i32 (...) @endspent()
%17 = load %struct.spwd*, %struct.spwd** %4
%18 = icmp eq %struct.spwd* %17, null
%19 = sext i1 %18 to i32
ret i32 %19
}