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

/* Variables and functions */
int ERANGE;
struct passwd *getpwent();
int /*<<< orphan*/ memcpy(struct passwd *, struct passwd *, int);
int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen,
               struct passwd **pwbufp) {
  struct passwd *pw;
  if ((pw = getpwent()) == NULL) {
    return ERANGE;
  }
  memcpy(pwbuf, pw, sizeof(*pw));
  *pwbufp = pwbuf;
  return 0;
}


x86 assembly (clang, -O0):
<getpwent_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x0,%al
call   1040 <getpwent@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    115e <getpwent_r+0x3e>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <getpwent_r+0x62>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpwent_r>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getpwent@plt>
test   %rax,%rax
je     114d <getpwent_r+0x2d>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    %rbx,(%r14)
jmp    1156 <getpwent_r+0x36>
mov    0x2e94(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@ERANGE = global i32 0
define i32 @getpwent_r(%struct.passwd* %0, i8* %1, i64 %2, %struct.passwd** %3) {
%5 = alloca i32
%6 = alloca %struct.passwd*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.passwd**
%10 = alloca %struct.passwd*
store %struct.passwd* %0, %struct.passwd** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store %struct.passwd** %3, %struct.passwd*** %9
%11 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %11, %struct.passwd** %10
%12 = icmp eq %struct.passwd* %11, null
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = load i32, i32* @ERANGE
store i32 %14, i32* %5
br label %21
15: ; preds = %4
%16 = load %struct.passwd*, %struct.passwd** %6
%17 = load %struct.passwd*, %struct.passwd** %10
%18 = call i32 @memcpy(%struct.passwd* %16, %struct.passwd* %17, i32 4)
%19 = load %struct.passwd*, %struct.passwd** %6
%20 = load %struct.passwd**, %struct.passwd*** %9
store %struct.passwd* %19, %struct.passwd** %20
store i32 0, i32* %5
br label %21
21: ; preds = %15, %13
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@ERANGE = global i32 0
define i32 @getpwent_r(%struct.passwd* %0, i8* nocapture readnone %1, i64 %2, %struct.passwd** nocapture writeonly %3) {
%5 = tail call %struct.passwd* (...) @getpwent()
%6 = icmp eq %struct.passwd* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load i32, i32* @ERANGE
br label %11
9: ; preds = %4
%10 = tail call i32 @memcpy(%struct.passwd* %0, %struct.passwd* %5, i32 4)
store %struct.passwd* %0, %struct.passwd** %3
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ 0, %9 ]
ret i32 %12
}