#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*/ endpwent();
struct spwd *getpwent();
int /*<<< orphan*/ setspent();
scalar_t__ strcmp(char const *, int /*<<< orphan*/);
struct spwd *my_getspnam(char const *name) {
  struct spwd *ptr = 0;
  setspent();
  while ((ptr = getpwent()) != NULL) {
    if (strcmp(name, ptr->sp_namp) == 0)
      break;
  }
  endpwent();
  return (ptr);
}


x86 assembly (clang, -O0):
<my_getspnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <setspent@plt>
mov    $0x0,%al
call   1050 <getpwent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1193 <my_getspnam+0x53>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    118e <my_getspnam+0x4e>
jmp    1193 <my_getspnam+0x53>
jmp    115b <my_getspnam+0x1b>
mov    $0x0,%al
call   1060 <endpwent@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_getspnam>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <setspent@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getpwent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116e <my_getspnam+0x2e>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1150 <my_getspnam+0x10>
xor    %eax,%eax
call   1060 <endpwent@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.spwd = type { i32 }
define %struct.spwd* @my_getspnam(i8* %0) {
%2 = tail call i32 (...) @setspent()
br label %3
3: ; preds = %6, %1
%4 = tail call %struct.spwd* (...) @getpwent()
%5 = icmp eq %struct.spwd* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.spwd, %struct.spwd* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @strcmp(i8* %0, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %6, %3
%12 = tail call i32 (...) @endpwent()
ret %struct.spwd* %4
}