#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int passwd_auth(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rfc1738_unescape(char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strchr(char *, char);
char *strtok(char *, char *);
int main(int argc, char **argv) {
  int auth = 0;
  char buf[256];
  char *user, *passwd, *p;
  setbuf(stdout, NULL);
  while (fgets(buf, 256, stdin) != NULL) {
    if ((p = strchr(buf, '\n')) != NULL)
      *p = '\0';
    if ((user = strtok(buf, " ")) == NULL) {
      printf("ERR\n");
      continue;
    }
    if ((passwd = strtok(NULL, "")) == NULL) {
      printf("ERR\n");
      continue;
    }
    rfc1738_unescape(user);
    rfc1738_unescape(passwd);
    auth = passwd_auth(user, passwd);
    if (auth == 0) {
      printf("ERR No such user\n");
    } else {
      if (auth == 2) {
        printf("ERR Wrong password\n");
      } else {
        printf("OK\n");
      }
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12e3 <main+0x163>
lea    -0x120(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x138(%rbp)
cmp    $0x0,%rax
je     1202 <main+0x82>
mov    -0x138(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x120(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    1237 <main+0xb7>
lea    0xdd5(%rip),%rdi
call   1060 <printf@plt>
jmp    11b2 <main+0x32>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdee(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x130(%rbp)
cmp    $0x0,%rax
jne    1269 <main+0xe9>
lea    0xda3(%rip),%rdi
call   1060 <printf@plt>
jmp    11b2 <main+0x32>
mov    -0x128(%rbp),%rdi
call   1030 <rfc1738_unescape@plt>
mov    -0x130(%rbp),%rdi
call   1030 <rfc1738_unescape@plt>
mov    -0x128(%rbp),%rdi
mov    -0x130(%rbp),%rsi
call   1090 <passwd_auth@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    12b2 <main+0x132>
lea    0xd5f(%rip),%rdi
call   1060 <printf@plt>
jmp    12de <main+0x15e>
cmpl   $0x2,-0x14(%rbp)
jne    12cd <main+0x14d>
lea    0xd56(%rip),%rdi
call   1060 <printf@plt>
jmp    12d9 <main+0x159>
lea    0xd59(%rip),%rdi
call   1060 <printf@plt>
jmp    12de <main+0x15e>
jmp    11b2 <main+0x32>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <setbuf@plt>
mov    0x2e40(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    11c4 <main+0x44>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    %rsp,%r12
lea    0xe32(%rip),%r14
lea    0xe54(%rip),%r15
jmp    11fa <main+0x7a>
nopw   0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    0x0(%rbp),%edx
mov    %r12,%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     11bd <main+0x3d>
mov    %r12,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     120f <main+0x8f>
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
call   1080 <strtok@plt>
mov    %r15,%rdi
test   %rax,%rax
je     11e0 <main+0x60>
mov    %rax,%rbx
xor    %edi,%edi
lea    0xdd3(%rip),%rsi
call   1080 <strtok@plt>
mov    %r15,%rdi
test   %rax,%rax
je     11e0 <main+0x60>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <rfc1738_unescape@plt>
mov    %r13,%rdi
call   1040 <rfc1738_unescape@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <passwd_auth@plt>
lea    0xda5(%rip),%rcx
cmp    $0x2,%eax
je     126c <main+0xec>
lea    0xd96(%rip),%rcx
lea    0xda5(%rip),%rdi
test   %eax,%eax
je     11e0 <main+0x60>
mov    %rcx,%rdi
jmp    11e0 <main+0x60>

LLVM IR (-O0):
@stdout = global i32 0
@stdin = global i32 0
@.str = [2 x i8] c" \00"
@.str.1 = [5 x i8] c"ERR\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [18 x i8] c"ERR No such user\0A\00"
@.str.4 = [20 x i8] c"ERR Wrong password\0A\00"
@.str.5 = [4 x i8] c"OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = load i32, i32* @stdout
%12 = call i32 @setbuf(i32 %11, i32* null)
br label %13
13: ; preds = %55, %33, %28, %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32* @fgets(i8* %14, i32 256, i32 %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %56
18: ; preds = %13
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = call i8* @strchr(i8* %19, i8 signext 10)
store i8* %20, i8** %10
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load i8*, i8** %10
store i8 0, i8* %23
br label %24
24: ; preds = %22, %18
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i8* @strtok(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %26, i8** %8
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %13
30: ; preds = %24
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
store i8* %31, i8** %9
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %13
35: ; preds = %30
%36 = load i8*, i8** %8
%37 = call i32 @rfc1738_unescape(i8* %36)
%38 = load i8*, i8** %9
%39 = call i32 @rfc1738_unescape(i8* %38)
%40 = load i8*, i8** %8
%41 = load i8*, i8** %9
%42 = call i32 @passwd_auth(i8* %40, i8* %41)
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %35
%46 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %55
47: ; preds = %35
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 2
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %54
52: ; preds = %47
%53 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %50
br label %55
55: ; preds = %54, %45
br label %13
56: ; preds = %13
%57 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
@.str = [2 x i8] c" \00"
@.str.2 = [1 x i8] zeroinitializer
@str = [3 x i8] c"OK\00"
@str.6 = [19 x i8] c"ERR Wrong password\00"
@str.7 = [17 x i8] c"ERR No such user\00"
@str.9 = [4 x i8] c"ERR\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @stdout
%6 = tail call i32 @setbuf(i32 %5, i32* null)
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %4, i32 256, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %34, label %10
10: ; preds = %2, %17
%11 = call i8* @strchr(i8* %4, i8 signext 10)
%12 = icmp eq i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i8 0, i8* %11
br label %14
14: ; preds = %13, %10
%15 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %14, %26, %23
%18 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.9, i64 0, i64 0), %23 ], [ %33, %26 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.9, i64 0, i64 0), %14 ]
%19 = call i32 @puts(i8* dereferenceable(1) %18)
%20 = load i32, i32* @stdin
%21 = call i32* @fgets(i8* %4, i32 256, i32 %20)
%22 = icmp eq i32* %21, null
br i1 %22, label %34, label %10
23: ; preds = %14
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %17, label %26
26: ; preds = %23
%27 = call i32 @rfc1738_unescape(i8* %15)
%28 = call i32 @rfc1738_unescape(i8* %24)
%29 = call i32 @passwd_auth(i8* %15, i8* %24)
%30 = icmp eq i32 %29, 2
%31 = select i1 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0)
%32 = icmp eq i32 %29, 0
%33 = select i1 %32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0), i8* %31
br label %17
34: ; preds = %17, %2
%35 = call i32 @exit(i32 0)
unreachable
}