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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int fprintf(int /*<<< orphan*/ *, char *, char *, char *, ...);
char *safestr(char *);
int fputpwent(const struct passwd *passwd, FILE *f) {
  int res;
  assert(passwd != NULL);
  assert(f != NULL);
  if (passwd->pw_name[0] == '+')
    res = fprintf(f, "%s:%s:::%s:%s:%s\n", safestr(passwd->pw_name),
                  safestr(passwd->pw_passwd), safestr(passwd->pw_gecos),
                  safestr(passwd->pw_dir), safestr(passwd->pw_shell));
  else
    res = fprintf(f, "%s:%s:%u:%u:%s:%s:%s\n", safestr(passwd->pw_name),
                  safestr(passwd->pw_passwd), passwd->pw_uid, passwd->pw_gid,
                  safestr(passwd->pw_gecos), safestr(passwd->pw_dir),
                  safestr(passwd->pw_shell));
  if (res < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<fputpwent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1200 <fputpwent+0xd0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <safestr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <safestr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <safestr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <safestr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1030 <safestr@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    0xe13(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    %eax,-0x1c(%rbp)
jmp    12a7 <fputpwent+0x177>
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <safestr@plt>
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <safestr@plt>
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c(%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <safestr@plt>
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <safestr@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1030 <safestr@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%rcx
mov    -0x60(%rbp),%r8d
mov    -0x5c(%rbp),%r9d
mov    -0x58(%rbp),%r11
mov    -0x50(%rbp),%r10
lea    0xd83(%rip),%rsi
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    12bd <fputpwent+0x18d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c4 <fputpwent+0x194>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputpwent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
mov    (%rbx),%rdi
mov    (%rdi),%bpl
call   1030 <safestr@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
call   1030 <safestr@plt>
mov    %rax,%r12
cmp    $0x2b,%bpl
jne    11cc <fputpwent+0x9c>
mov    0x10(%rbx),%rdi
call   1030 <safestr@plt>
mov    %rax,%r13
mov    0x18(%rbx),%rdi
call   1030 <safestr@plt>
mov    %rax,%rbp
mov    0x20(%rbx),%rdi
call   1030 <safestr@plt>
mov    %rax,%rbx
sub    $0x8,%rsp
lea    0xe51(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    %rbp,%r9
xor    %eax,%eax
push   %rbx
call   1050 <fprintf@plt>
add    $0x10,%rsp
jmp    122a <fputpwent+0xfa>
mov    0x28(%rbx),%ebp
mov    0x2c(%rbx),%eax
mov    %eax,0xc(%rsp)
mov    0x10(%rbx),%rdi
call   1030 <safestr@plt>
mov    %rax,0x10(%rsp)
mov    0x18(%rbx),%rdi
call   1030 <safestr@plt>
mov    %rax,%r13
mov    0x20(%rbx),%rdi
call   1030 <safestr@plt>
mov    %rax,%rbx
sub    $0x8,%rsp
lea    0xe0b(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %ebp,%r8d
mov    0x14(%rsp),%r9d
xor    %eax,%eax
push   %rbx
push   %r13
push   0x28(%rsp)
call   1050 <fprintf@plt>
add    $0x20,%rsp
sar    $0x1f,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i8*, i8*, i8*, i32, i32 }
@.str = [18 x i8] c"%s:%s:::%s:%s:%s\0A\00"
@.str.1 = [22 x i8] c"%s:%s:%u:%u:%s:%s:%s\0A\00"
define i32 @fputpwent(%struct.passwd* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.passwd*
%5 = alloca i32*
%6 = alloca i32
store %struct.passwd* %0, %struct.passwd** %4
store i32* %1, i32** %5
%7 = load %struct.passwd*, %struct.passwd** %4
%8 = icmp ne %struct.passwd* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%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 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 43
br i1 %21, label %22, label %45
22: ; preds = %2
%23 = load i32*, i32** %5
%24 = load %struct.passwd*, %struct.passwd** %4
%25 = getelementptr inbounds %struct.passwd, %struct.passwd* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = call i8* @safestr(i8* %26)
%28 = load %struct.passwd*, %struct.passwd** %4
%29 = getelementptr inbounds %struct.passwd, %struct.passwd* %28, i32 0, i32 1
%30 = load i8*, i8** %29
%31 = call i8* @safestr(i8* %30)
%32 = load %struct.passwd*, %struct.passwd** %4
%33 = getelementptr inbounds %struct.passwd, %struct.passwd* %32, i32 0, i32 2
%34 = load i8*, i8** %33
%35 = call i8* @safestr(i8* %34)
%36 = load %struct.passwd*, %struct.passwd** %4
%37 = getelementptr inbounds %struct.passwd, %struct.passwd* %36, i32 0, i32 3
%38 = load i8*, i8** %37
%39 = call i8* @safestr(i8* %38)
%40 = load %struct.passwd*, %struct.passwd** %4
%41 = getelementptr inbounds %struct.passwd, %struct.passwd* %40, i32 0, i32 4
%42 = load i8*, i8** %41
%43 = call i8* @safestr(i8* %42)
%44 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %31, i8* %35, i8* %39, i8* %43)
store i32 %44, i32* %6
br label %74
45: ; preds = %2
%46 = load i32*, i32** %5
%47 = load %struct.passwd*, %struct.passwd** %4
%48 = getelementptr inbounds %struct.passwd, %struct.passwd* %47, i32 0, i32 0
%49 = load i8*, i8** %48
%50 = call i8* @safestr(i8* %49)
%51 = load %struct.passwd*, %struct.passwd** %4
%52 = getelementptr inbounds %struct.passwd, %struct.passwd* %51, i32 0, i32 1
%53 = load i8*, i8** %52
%54 = call i8* @safestr(i8* %53)
%55 = load %struct.passwd*, %struct.passwd** %4
%56 = getelementptr inbounds %struct.passwd, %struct.passwd* %55, i32 0, i32 5
%57 = load i32, i32* %56
%58 = load %struct.passwd*, %struct.passwd** %4
%59 = getelementptr inbounds %struct.passwd, %struct.passwd* %58, i32 0, i32 6
%60 = load i32, i32* %59
%61 = load %struct.passwd*, %struct.passwd** %4
%62 = getelementptr inbounds %struct.passwd, %struct.passwd* %61, i32 0, i32 2
%63 = load i8*, i8** %62
%64 = call i8* @safestr(i8* %63)
%65 = load %struct.passwd*, %struct.passwd** %4
%66 = getelementptr inbounds %struct.passwd, %struct.passwd* %65, i32 0, i32 3
%67 = load i8*, i8** %66
%68 = call i8* @safestr(i8* %67)
%69 = load %struct.passwd*, %struct.passwd** %4
%70 = getelementptr inbounds %struct.passwd, %struct.passwd* %69, i32 0, i32 4
%71 = load i8*, i8** %70
%72 = call i8* @safestr(i8* %71)
%73 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %50, i8* %54, i32 %57, i32 %60, i8* %64, i8* %68, i8* %72)
store i32 %73, i32* %6
br label %74
74: ; preds = %45, %22
%75 = load i32, i32* %6
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %74
store i32 -1, i32* %3
br label %79
78: ; preds = %74
store i32 0, i32* %3
br label %79
79: ; preds = %78, %77
%80 = load i32, i32* %3
ret i32 %80
}

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