#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 {
  char *pw_name;
  char *pw_passwd;
  int pw_uid;
  int pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, char *, char *, int, int,
                   char *, char *, char *);
int putpwent(const struct passwd *passwd, FILE *f) {
  if (passwd == NULL || f == NULL) {
    errno = EINVAL;
    return -1;
  }
  if (fprintf(f, "%s:%s:%u:%u:%s:%s:%s\n", passwd->pw_name, passwd->pw_passwd,
              passwd->pw_uid, passwd->pw_gid, passwd->pw_gecos, passwd->pw_dir,
              passwd->pw_shell) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<putpwent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1136 <putpwent+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1154 <putpwent+0x44>
mov    0x2e9b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e9a(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <putpwent+0xb6>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%r9d
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r11
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%r10
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rax
lea    0xe6a(%rip),%rsi
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <fprintf@plt>
cmp    $0x0,%rax
jge    11bf <putpwent+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <putpwent+0xb6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putpwent>:
sub    $0x18,%rsp
test   %rdi,%rdi
je     1159 <putpwent+0x49>
test   %rsi,%rsi
je     1159 <putpwent+0x49>
mov    (%rdi),%rdx
mov    0x8(%rdi),%rcx
mov    0x10(%rdi),%r8d
mov    0x14(%rdi),%r9d
movups 0x18(%rdi),%xmm0
mov    0x28(%rdi),%rax
mov    %rax,0x10(%rsp)
movups %xmm0,(%rsp)
lea    0xebb(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1030 <fprintf@plt>
sar    $0x3f,%rax
add    $0x18,%rsp
ret
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    0x2e77(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@EINVAL = global i32 0
@errno = global i32 0
@.str = [22 x i8] c"%s:%s:%u:%u:%s:%s:%s\0A\00"
define i32 @putpwent(%struct.passwd* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.passwd*
%5 = alloca i32*
store %struct.passwd* %0, %struct.passwd** %4
store i32* %1, i32** %5
%6 = load %struct.passwd*, %struct.passwd** %4
%7 = icmp eq %struct.passwd* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = load i32, i32* @EINVAL
store i32 %12, i32* @errno
store i32 -1, i32* %3
br label %40
13: ; preds = %8
%14 = load i32*, i32** %5
%15 = load %struct.passwd*, %struct.passwd** %4
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = load %struct.passwd*, %struct.passwd** %4
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %18, i32 0, i32 1
%20 = load i8*, i8** %19
%21 = load %struct.passwd*, %struct.passwd** %4
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %21, i32 0, i32 2
%23 = load i32, i32* %22
%24 = load %struct.passwd*, %struct.passwd** %4
%25 = getelementptr inbounds %struct.passwd, %struct.passwd* %24, i32 0, i32 3
%26 = load i32, i32* %25
%27 = load %struct.passwd*, %struct.passwd** %4
%28 = getelementptr inbounds %struct.passwd, %struct.passwd* %27, i32 0, i32 4
%29 = load i8*, i8** %28
%30 = load %struct.passwd*, %struct.passwd** %4
%31 = getelementptr inbounds %struct.passwd, %struct.passwd* %30, i32 0, i32 5
%32 = load i8*, i8** %31
%33 = load %struct.passwd*, %struct.passwd** %4
%34 = getelementptr inbounds %struct.passwd, %struct.passwd* %33, i32 0, i32 6
%35 = load i8*, i8** %34
%36 = call i64 @fprintf(i32* %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %20, i32 %23, i32 %26, i8* %29, i8* %32, i8* %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %13
store i32 -1, i32* %3
br label %40
39: ; preds = %13
store i32 0, i32* %3
br label %40
40: ; preds = %39, %38, %11
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i32, i32, i8*, i8*, i8* }
@EINVAL = global i32 0
@errno = global i32 0
@.str = [22 x i8] c"%s:%s:%u:%u:%s:%s:%s\0A\00"
define i32 @putpwent(%struct.passwd* %0, i32* %1) {
%3 = icmp eq %struct.passwd* %0, null
%4 = icmp eq i32* %1, null
%5 = or i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %26
8: ; preds = %2
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 2
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 3
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 4
%18 = load i8*, i8** %17
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 5
%20 = load i8*, i8** %19
%21 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 6
%22 = load i8*, i8** %21
%23 = tail call i64 @fprintf(i32* %1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %12, i32 %14, i32 %16, i8* %18, i8* %20, i8* %22)
%24 = ashr i64 %23, 63
%25 = trunc i64 %24 to i32
br label %26
26: ; preds = %8, %6
%27 = phi i32 [ -1, %6 ], [ %25, %8 ]
ret i32 %27
}