#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 spwd {
  int /*<<< orphan*/ sp_pwdp;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ STDIN_FILENO;
char *crypt(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct spwd *getspnam(char *);
scalar_t__ isatty(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct spwd *sp;
  if (isatty(STDIN_FILENO) || argc != 2) {
    fprintf(stderr, "This binary is not designed for running in this way\n"
                    "-- the system administrator has been informed\n");
    sleep(10);
    return EXIT_FAILURE;
  }
  if (argc < 2) {
    fprintf(stderr, "%s username \n", argv[0]);
    return (EXIT_FAILURE);
  }
  if ((sp = getspnam(argv[1])) == (struct spwd *)0) {
    fprintf(stderr, "getspnam: unknown <%s>\n", argv[1]);
    return (EXIT_FAILURE);
  }
  char pw[1000 + 1];
  while (scanf("%s", pw) > 0) {
    const char *crypt_password;
    printf("Trying: <%s>\n", pw);
    if (((crypt_password = crypt(pw, sp->sp_pwdp)) != NULL) &&
        strcmp(crypt_password, sp->sp_pwdp) == 0) {
      printf("This one worked! %s\n", pw);
      return (EXIT_SUCCESS);
    }
  }
  printf("Failed!!!\n");
  return (EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1030 <isatty@plt>
cmp    $0x0,%rax
jne    11bb <main+0x3b>
cmpl   $0x2,-0x8(%rbp)
je     11ed <main+0x6d>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xa,%edi
call   10a0 <sleep@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132c <main+0x1ac>
cmpl   $0x2,-0x8(%rbp)
jge    1226 <main+0xa6>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132c <main+0x1ac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <getspnam@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1271 <main+0xf1>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132c <main+0x1ac>
jmp    1276 <main+0xf6>
lea    -0x410(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1080 <scanf@plt>
cmp    $0x0,%rax
jle    1312 <main+0x192>
lea    -0x410(%rbp),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1040 <crypt@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
je     130d <main+0x18d>
mov    -0x418(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    130d <main+0x18d>
lea    -0x410(%rbp),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132c <main+0x1ac>
jmp    1276 <main+0xf6>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f0,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1040 <isatty@plt>
cmp    $0x2,%ebp
jne    1267 <main+0xd7>
test   %rax,%rax
jne    1267 <main+0xd7>
mov    0x8(%rbx),%rdi
call   10a0 <getspnam@plt>
test   %rax,%rax
je     1298 <main+0x108>
mov    %rax,%r15
lea    0xe9b(%rip),%rdi
mov    %rsp,%rsi
call   1090 <scanf@plt>
test   %rax,%rax
jle    128a <main+0xfa>
lea    0xe86(%rip),%r14
mov    %rsp,%rbx
lea    0xe79(%rip),%r12
jmp    1220 <main+0x90>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
test   %rax,%rax
jle    128a <main+0xfa>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <crypt@plt>
test   %rax,%rax
je     1210 <main+0x80>
mov    (%r15),%esi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1210 <main+0x80>
lea    0xe38(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d6b(%rip),%rax
jmp    12ba <main+0x12a>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xa,%edi
call   10b0 <sleep@plt>
jmp    12b3 <main+0x123>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
jmp    12b3 <main+0x123>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdb7(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.spwd = type { i32 }
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [99 x i8] c"This binary is not designed for running in this way\0A-- the system administrator has been informed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"%s username \0A\00"
@.str.2 = [24 x i8] c"getspnam: unknown <%s>\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [14 x i8] c"Trying: <%s>\0A\00"
@.str.5 = [21 x i8] c"This one worked! %s\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.6 = [11 x i8] c"Failed!!!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.spwd*
%7 = alloca [1001 x i8]
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @STDIN_FILENO
%10 = call i64 @isatty(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %12, %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @sleep(i32 10)
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %72
20: ; preds = %12
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 2
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %72
30: ; preds = %20
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call %struct.spwd* @getspnam(i8* %33)
store %struct.spwd* %34, %struct.spwd** %6
%35 = icmp eq %struct.spwd* %34, null
br i1 %35, label %36, label %43
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
store i32 %42, i32* %3
br label %72
43: ; preds = %30
br label %44
44: ; preds = %68, %43
%45 = getelementptr inbounds [1001 x i8], [1001 x i8]* %7, i64 0, i64 0
%46 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = icmp sgt i64 %46, 0
br i1 %47, label %48, label %69
48: ; preds = %44
%49 = getelementptr inbounds [1001 x i8], [1001 x i8]* %7, i64 0, i64 0
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = getelementptr inbounds [1001 x i8], [1001 x i8]* %7, i64 0, i64 0
%52 = load %struct.spwd*, %struct.spwd** %6
%53 = getelementptr inbounds %struct.spwd, %struct.spwd* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i8* @crypt(i8* %51, i32 %54)
store i8* %55, i8** %8
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %68
57: ; preds = %48
%58 = load i8*, i8** %8
%59 = load %struct.spwd*, %struct.spwd** %6
%60 = getelementptr inbounds %struct.spwd, %struct.spwd* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i64 @strcmp(i8* %58, i32 %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %57
%65 = getelementptr inbounds [1001 x i8], [1001 x i8]* %7, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %65)
%67 = load i32, i32* @EXIT_SUCCESS
store i32 %67, i32* %3
br label %72
68: ; preds = %57, %48
br label %44
69: ; preds = %44
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%71 = load i32, i32* @EXIT_FAILURE
store i32 %71, i32* %3
br label %72
72: ; preds = %69, %64, %36, %23, %15
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
%struct.spwd = type { i32 }
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [99 x i8] c"This binary is not designed for running in this way\0A-- the system administrator has been informed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"getspnam: unknown <%s>\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [14 x i8] c"Trying: <%s>\0A\00"
@.str.5 = [21 x i8] c"This one worked! %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [10 x i8] c"Failed!!!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1001 x i8]
%4 = load i32, i32* @STDIN_FILENO
%5 = tail call i64 @isatty(i32 %4)
%6 = icmp ne i64 %5, 0
%7 = icmp ne i32 %0, 2
%8 = or i1 %7, %6
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @sleep(i32 10)
%13 = load i32, i32* @EXIT_FAILURE
br label %49
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call %struct.spwd* @getspnam(i8* %16)
%18 = icmp eq %struct.spwd* %17, null
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %15
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
br label %49
24: ; preds = %14
%25 = getelementptr inbounds [1001 x i8], [1001 x i8]* %3, i64 0, i64 0
%26 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = getelementptr inbounds %struct.spwd, %struct.spwd* %17, i64 0, i32 0
br label %30
30: ; preds = %28, %41
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%32 = load i32, i32* %29
%33 = call i8* @crypt(i8* %25, i32 %32)
%34 = icmp eq i8* %33, null
br i1 %34, label %41, label %35
35: ; preds = %30
%36 = load i32, i32* %29
%37 = call i64 @strcmp(i8* %33, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %25)
br label %46
41: ; preds = %30, %35
%42 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%43 = icmp sgt i64 %42, 0
br i1 %43, label %30, label %44
44: ; preds = %41, %24
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %46
46: ; preds = %39, %44
%47 = phi i32* [ @EXIT_FAILURE, %44 ], [ @EXIT_SUCCESS, %39 ]
%48 = load i32, i32* %47
br label %49
49: ; preds = %46, %19, %9
%50 = phi i32 [ %13, %9 ], [ %23, %19 ], [ %48, %46 ]
ret i32 %50
}