#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
int passwd_read(FILE *fp, char *name, char *pwd) {
  char s[1024], *p;
  if ((fgets(s, 1024, fp)) == NULL) {
    return -1;
  }
  if ((p = strchr(s, ':')) == NULL)
    return -1;
  *p++ = 0;
  strcpy(name, s);
  strcpy(pwd, p);
  if ((p = strrchr(pwd, '\n')) != NULL)
    *p = 0;
  return 0;
}


x86 assembly (clang, -O0):
<passwd_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1182 <passwd_read+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <passwd_read+0xd8>
lea    -0x420(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    11b0 <passwd_read+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <passwd_read+0xd8>
mov    -0x428(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x428(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
je     1211 <passwd_read+0xd1>
mov    -0x428(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passwd_read>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rdx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     11b4 <passwd_read+0x74>
mov    %rsp,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b4 <passwd_read+0x74>
mov    %rax,%rbp
add    $0x1,%rbp
movb   $0x0,(%rax)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strrchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11b4 <passwd_read+0x74>
movb   $0x0,(%rax)
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @passwd_read(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%11 = load i32*, i32** %5
%12 = call i32* @fgets(i8* %10, i32 1024, i32* %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %35
15: ; preds = %3
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%17 = call i8* @strchr(i8* %16, i8 signext 58)
store i8* %17, i8** %9
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %4
br label %35
20: ; preds = %15
%21 = load i8*, i8** %9
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %9
store i8 0, i8* %21
%23 = load i8*, i8** %6
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = call i32 @strcpy(i8* %23, i8* %24)
%26 = load i8*, i8** %7
%27 = load i8*, i8** %9
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = load i8*, i8** %7
%30 = call i8* @strrchr(i8* %29, i8 signext 10)
store i8* %30, i8** %9
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = load i8*, i8** %9
store i8 0, i8* %33
br label %34
34: ; preds = %32, %20
store i32 0, i32* %4
br label %35
35: ; preds = %34, %19, %14
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @passwd_read(i32* nocapture %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32* @fgets(i8* %5, i32 1024, i32* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %18, label %8
8: ; preds = %3
%9 = call i8* @strchr(i8* %5, i8 signext 58)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
store i8 0, i8* %9
%13 = call i32 @strcpy(i8* %1, i8* %5)
%14 = call i32 @strcpy(i8* %2, i8* %12)
%15 = call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 10)
%16 = icmp eq i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %11
store i8 0, i8* %15
br label %18
18: ; preds = %11, %17, %8, %3
%19 = phi i32 [ -1, %3 ], [ -1, %8 ], [ 0, %17 ], [ 0, %11 ]
ret i32 %19
}