#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 */
char *crypt(char *, char *);
int strlen(char *);
int detect_std_crypt(void) {
  char salt[3], *p;
  salt[0] = 'A';
  salt[1] = 'B';
  salt[2] = 0;
  p = crypt("std_crypt() test!", salt);
  if (p != NULL) {
    if (strlen(p) != 13)
      return 0;
    if (p[0] != salt[0] || p[1] != salt[1])
      return 0;
  } else {
    p = crypt("stdcrypt", salt);
    if (p != NULL) {
      if (strlen(p) != 13)
        return 0;
      if (p[0] != salt[0] || p[1] != salt[1])
        return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<detect_std_crypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x41,-0x7(%rbp)
movb   $0x42,-0x6(%rbp)
movb   $0x0,-0x5(%rbp)
lea    -0x7(%rbp),%rsi
lea    0xec1(%rip),%rdi
call   1030 <crypt@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a9 <detect_std_crypt+0x89>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xd,%eax
je     1171 <detect_std_crypt+0x51>
movl   $0x0,-0x4(%rbp)
jmp    122a <detect_std_crypt+0x10a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x7(%rbp),%ecx
cmp    %ecx,%eax
jne    1198 <detect_std_crypt+0x78>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
movsbl -0x6(%rbp),%ecx
cmp    %ecx,%eax
je     11a4 <detect_std_crypt+0x84>
movl   $0x0,-0x4(%rbp)
jmp    122a <detect_std_crypt+0x10a>
jmp    1223 <detect_std_crypt+0x103>
lea    -0x7(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1030 <crypt@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     121e <detect_std_crypt+0xfe>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xd,%eax
je     11e6 <detect_std_crypt+0xc6>
movl   $0x0,-0x4(%rbp)
jmp    122a <detect_std_crypt+0x10a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x7(%rbp),%ecx
cmp    %ecx,%eax
jne    120d <detect_std_crypt+0xed>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
movsbl -0x6(%rbp),%ecx
cmp    %ecx,%eax
je     1219 <detect_std_crypt+0xf9>
movl   $0x0,-0x4(%rbp)
jmp    122a <detect_std_crypt+0x10a>
jmp    121e <detect_std_crypt+0xfe>
jmp    1223 <detect_std_crypt+0x103>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_std_crypt>:
push   %rbx
sub    $0x10,%rsp
movw   $0x4241,0xd(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xec8(%rip),%rdi
lea    0xd(%rsp),%rsi
call   1030 <crypt@plt>
test   %rax,%rax
jne    115d <detect_std_crypt+0x3d>
lea    0xec4(%rip),%rdi
lea    0xd(%rsp),%rsi
call   1030 <crypt@plt>
test   %rax,%rax
je     1182 <detect_std_crypt+0x62>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xd,%ecx
jne    1187 <detect_std_crypt+0x67>
mov    (%rbx),%cl
cmp    0xd(%rsp),%cl
jne    1187 <detect_std_crypt+0x67>
mov    0x1(%rbx),%cl
cmp    0xe(%rsp),%cl
jne    1187 <detect_std_crypt+0x67>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"std_crypt() test!\00"
@.str.1 = [9 x i8] c"stdcrypt\00"
define i32 @detect_std_crypt() {
%1 = alloca i32
%2 = alloca [3 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
store i8 65, i8* %4
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 66, i8* %5
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
store i8 0, i8* %6
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%8 = call i8* @crypt(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %36
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp ne i32 %13, 13
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 0, i32* %1
br label %68
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %20, %23
br i1 %24, label %34, label %25
25: ; preds = %16
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %29, %32
br i1 %33, label %34, label %35
34: ; preds = %25, %16
store i32 0, i32* %1
br label %68
35: ; preds = %25
br label %67
36: ; preds = %0
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%38 = call i8* @crypt(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %37)
store i8* %38, i8** %3
%39 = load i8*, i8** %3
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %66
41: ; preds = %36
%42 = load i8*, i8** %3
%43 = call i32 @strlen(i8* %42)
%44 = icmp ne i32 %43, 13
br i1 %44, label %45, label %46
45: ; preds = %41
store i32 0, i32* %1
br label %68
46: ; preds = %41
%47 = load i8*, i8** %3
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %50, %53
br i1 %54, label %64, label %55
55: ; preds = %46
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %59, %62
br i1 %63, label %64, label %65
64: ; preds = %55, %46
store i32 0, i32* %1
br label %68
65: ; preds = %55
br label %66
66: ; preds = %65, %36
br label %67
67: ; preds = %66, %35
store i32 1, i32* %1
br label %68
68: ; preds = %67, %64, %45, %34, %15
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
@.str = [18 x i8] c"std_crypt() test!\00"
@.str.1 = [9 x i8] c"stdcrypt\00"
define i32 @detect_std_crypt() {
%1 = alloca [3 x i8]
%2 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
store i8 65, i8* %2
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
store i8 66, i8* %3
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
store i8 0, i8* %4
%5 = call i8* @crypt(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %19, label %7
7: ; preds = %0
%8 = call i32 @strlen(i8* %5)
%9 = icmp eq i32 %8, 13
br i1 %9, label %10, label %35
10: ; preds = %7
%11 = load i8, i8* %5
%12 = load i8, i8* %2
%13 = icmp eq i8 %11, %12
br i1 %13, label %14, label %35
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %5, i64 1
%16 = load i8, i8* %15
%17 = load i8, i8* %3
%18 = icmp eq i8 %16, %17
br i1 %18, label %34, label %35
19: ; preds = %0
%20 = call i8* @crypt(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%21 = icmp eq i8* %20, null
br i1 %21, label %34, label %22
22: ; preds = %19
%23 = call i32 @strlen(i8* %20)
%24 = icmp eq i32 %23, 13
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i8, i8* %20
%27 = load i8, i8* %2
%28 = icmp eq i8 %26, %27
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = getelementptr inbounds i8, i8* %20, i64 1
%31 = load i8, i8* %30
%32 = load i8, i8* %3
%33 = icmp eq i8 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %19, %29, %14
br label %35
35: ; preds = %25, %29, %22, %10, %14, %7, %34
%36 = phi i32 [ 1, %34 ], [ 0, %7 ], [ 0, %14 ], [ 0, %10 ], [ 0, %22 ], [ 0, %29 ], [ 0, %25 ]
ret i32 %36
}