#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;
  void *pw_gid;
  void *pw_uid;
};

/* Variables and functions */
void *atoi(char *);
int parsePasswdLine(char *line, struct passwd *pw_buf) {
  char *fPtr = line;
  char *prevPtr = line;
  int fieldN = 0;
  while ((*fPtr != '\n') && (*fPtr != 0)) {
    switch (fieldN) {
    case 0:
      pw_buf->pw_name = prevPtr;
      break;
    case 1:
      pw_buf->pw_passwd = prevPtr;
      break;
    case 2:
      pw_buf->pw_uid = atoi(prevPtr);
      break;
    case 3:
      pw_buf->pw_gid = atoi(prevPtr);
      break;
    case 4:
      pw_buf->pw_gecos = prevPtr;
      break;
    case 5:
      pw_buf->pw_dir = prevPtr;
      break;
    case 6:
      pw_buf->pw_shell = prevPtr;
      break;
    case 7:
      return -1;
      break;
    }
    fPtr++;
    if (*fPtr == ':') {
      fieldN++;
      *fPtr = 0;
      fPtr++;
      prevPtr = fPtr;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parsePasswdLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x2d(%rbp)
je     115c <parsePasswdLine+0x4c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    116c <parsePasswdLine+0x5c>
jmp    1268 <parsePasswdLine+0x158>
mov    -0x2c(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0x7,%rax
ja     1223 <parsePasswdLine+0x113>
mov    -0x38(%rbp),%rax
lea    0xe78(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1223 <parsePasswdLine+0x113>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    1223 <parsePasswdLine+0x113>
mov    -0x28(%rbp),%rdi
call   1030 <atoi@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x30(%rax)
jmp    1223 <parsePasswdLine+0x113>
mov    -0x28(%rbp),%rdi
call   1030 <atoi@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x28(%rax)
jmp    1223 <parsePasswdLine+0x113>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
jmp    1223 <parsePasswdLine+0x113>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
jmp    1223 <parsePasswdLine+0x113>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x20(%rax)
jmp    1223 <parsePasswdLine+0x113>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <parsePasswdLine+0x15f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1263 <parsePasswdLine+0x153>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1137 <parsePasswdLine+0x27>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsePasswdLine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
xor    %ebp,%ebp
lea    0xed9(%rip),%r15
lea    0x1(%r12),%rax
jmp    1149 <parsePasswdLine+0x39>
mov    %r12,0x20(%r14)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbx),%rax
cmpb   $0x3a,(%rbx)
je     11b0 <parsePasswdLine+0xa0>
mov    %rax,%rbx
movzbl -0x1(%rax),%ecx
xor    %eax,%eax
test   %cl,%cl
je     11bf <parsePasswdLine+0xaf>
cmp    $0xa,%cl
je     11bf <parsePasswdLine+0xaf>
cmp    $0x7,%ebp
ja     1140 <parsePasswdLine+0x30>
mov    $0xffffffff,%eax
mov    %ebp,%ecx
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    %r12,(%r14)
jmp    1140 <parsePasswdLine+0x30>
mov    %r12,0x8(%r14)
jmp    1140 <parsePasswdLine+0x30>
mov    %r12,%rdi
call   1030 <atoi@plt>
mov    %rax,0x30(%r14)
jmp    1140 <parsePasswdLine+0x30>
mov    %r12,%rdi
call   1030 <atoi@plt>
mov    %rax,0x28(%r14)
jmp    1140 <parsePasswdLine+0x30>
mov    %r12,0x10(%r14)
jmp    1140 <parsePasswdLine+0x30>
mov    %r12,0x18(%r14)
jmp    1140 <parsePasswdLine+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
movb   $0x0,-0x1(%rax)
mov    %rax,%r12
jmp    1127 <parsePasswdLine+0x17>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8*, i8*, i8*, i8*, i8*, i8*, i8* }
define i32 @parsePasswdLine(i8* %0, %struct.passwd* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.passwd*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store %struct.passwd* %1, %struct.passwd** %5
%9 = load i8*, i8** %4
store i8* %9, i8** %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
store i32 0, i32* %8
br label %11
11: ; preds = %70, %2
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br label %21
21: ; preds = %16, %11
%22 = phi i1 [ false, %11 ], [ %20, %16 ]
br i1 %22, label %23, label %71
23: ; preds = %21
%24 = load i32, i32* %8
switch i32 %24, label %56 [
i32 0, label %25
i32 1, label %29
i32 2, label %33
i32 3, label %38
i32 4, label %43
i32 5, label %47
i32 6, label %51
i32 7, label %55
]
25: ; preds = %23
%26 = load i8*, i8** %7
%27 = load %struct.passwd*, %struct.passwd** %5
%28 = getelementptr inbounds %struct.passwd, %struct.passwd* %27, i32 0, i32 0
store i8* %26, i8** %28
br label %56
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = load %struct.passwd*, %struct.passwd** %5
%32 = getelementptr inbounds %struct.passwd, %struct.passwd* %31, i32 0, i32 1
store i8* %30, i8** %32
br label %56
33: ; preds = %23
%34 = load i8*, i8** %7
%35 = call i8* @atoi(i8* %34)
%36 = load %struct.passwd*, %struct.passwd** %5
%37 = getelementptr inbounds %struct.passwd, %struct.passwd* %36, i32 0, i32 6
store i8* %35, i8** %37
br label %56
38: ; preds = %23
%39 = load i8*, i8** %7
%40 = call i8* @atoi(i8* %39)
%41 = load %struct.passwd*, %struct.passwd** %5
%42 = getelementptr inbounds %struct.passwd, %struct.passwd* %41, i32 0, i32 5
store i8* %40, i8** %42
br label %56
43: ; preds = %23
%44 = load i8*, i8** %7
%45 = load %struct.passwd*, %struct.passwd** %5
%46 = getelementptr inbounds %struct.passwd, %struct.passwd* %45, i32 0, i32 2
store i8* %44, i8** %46
br label %56
47: ; preds = %23
%48 = load i8*, i8** %7
%49 = load %struct.passwd*, %struct.passwd** %5
%50 = getelementptr inbounds %struct.passwd, %struct.passwd* %49, i32 0, i32 3
store i8* %48, i8** %50
br label %56
51: ; preds = %23
%52 = load i8*, i8** %7
%53 = load %struct.passwd*, %struct.passwd** %5
%54 = getelementptr inbounds %struct.passwd, %struct.passwd* %53, i32 0, i32 4
store i8* %52, i8** %54
br label %56
55: ; preds = %23
store i32 -1, i32* %3
br label %72
56: ; preds = %23, %51, %47, %43, %38, %33, %29, %25
%57 = load i8*, i8** %6
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %6
%59 = load i8*, i8** %6
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 58
br i1 %62, label %63, label %70
63: ; preds = %56
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
%66 = load i8*, i8** %6
store i8 0, i8* %66
%67 = load i8*, i8** %6
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %6
%69 = load i8*, i8** %6
store i8* %69, i8** %7
br label %70
70: ; preds = %63, %56
br label %11
71: ; preds = %21
store i32 0, i32* %3
br label %72
72: ; preds = %71, %55
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8*, i8*, i8*, i8*, i8*, i8* }
define i32 @parsePasswdLine(i8* %0, %struct.passwd* nocapture writeonly %1) {
%3 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 4
%4 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 3
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 2
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 5
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 6
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 1
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %1, i64 0, i32 0
br label %10
10: ; preds = %30, %2
%11 = phi i8* [ %32, %30 ], [ %0, %2 ]
%12 = phi i32 [ %31, %30 ], [ 0, %2 ]
br label %13
13: ; preds = %10, %26
%14 = phi i8* [ %27, %26 ], [ %11, %10 ]
%15 = load i8, i8* %14
switch i8 %15, label %16 [
i8 10, label %33
i8 0, label %33
]
16: ; preds = %13
switch i32 %12, label %26 [
i32 0, label %17
i32 1, label %18
i32 2, label %19
i32 3, label %21
i32 4, label %23
i32 5, label %24
i32 6, label %25
i32 7, label %33
]
17: ; preds = %16
store i8* %11, i8** %9
br label %26
18: ; preds = %16
store i8* %11, i8** %8
br label %26
19: ; preds = %16
%20 = tail call i8* @atoi(i8* %11)
store i8* %20, i8** %7
br label %26
21: ; preds = %16
%22 = tail call i8* @atoi(i8* %11)
store i8* %22, i8** %6
br label %26
23: ; preds = %16
store i8* %11, i8** %5
br label %26
24: ; preds = %16
store i8* %11, i8** %4
br label %26
25: ; preds = %16
store i8* %11, i8** %3
br label %26
26: ; preds = %16, %25, %24, %23, %21, %19, %18, %17
%27 = getelementptr inbounds i8, i8* %14, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 58
br i1 %29, label %30, label %13
30: ; preds = %26
%31 = add nuw nsw i32 %12, 1
store i8 0, i8* %27
%32 = getelementptr inbounds i8, i8* %14, i64 2
br label %10
33: ; preds = %13, %13, %16
%34 = phi i32 [ -1, %16 ], [ 0, %13 ], [ 0, %13 ]
ret i32 %34
}