#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*/ printf(char *, ...);
int random();
int strlen(char *);
int main() {
  int i, j, edi;
  char buf[50], ch;
  char out[50];
  unsigned char check;
  int ret = 0, val, len, rem;
  int magic;
  int k;
  unsigned char arr[] = {0x6a, 0xfb, 0x4c, 0x8d, 0x58, 0x0f, 0xd4,
                         0xe8, 0x94, 0x98, 0xee, 0x6b, 0x18, 0x30,
                         0xe0, 0x55, 0xc5, 0x28, 0x0e};
  for (i = 0; i < 19; i++)
    out[i] = 'x';
  out[i] = '\0';
  len = strlen(out);
  if (len == 19)
    ret = 1;
  for (i = 10; i > 0; i--) {
    int m2;
    val = random();
    rem = val % 19;
    check = arr[rem] & 0xff;
    ch = buf[rem++];
    j = 0;
    magic = 0;
    printf("rem = %d\n", rem);
    while (j < rem) {
      magic *= 1828812941;
      magic += 12345;
      j++;
    }
    m2 = magic;
    magic ^= ch;
    if ((magic & 0xff) != (check & 0xff))
      ret = 0;
    out[rem - 1] = (m2 & 0xff) ^ (check & 0xff);
  }
  printf("Password: %s\n", out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x98(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0xc0(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0xb8(%rbp)
mov    0xea1(%rip),%ax
mov    %ax,-0xb0(%rbp)
mov    0xe96(%rip),%al
mov    %al,-0xae(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x13,-0x8(%rbp)
jge    11ad <main+0x7d>
movslq -0x8(%rbp),%rax
movb   $0x78,-0x90(%rbp,%rax,1)
78
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1189 <main+0x59>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xa0(%rbp)
cmpl   $0x13,-0xa0(%rbp)
jne    11e2 <main+0xb2>
movl   $0x1,-0x98(%rbp)
movl   $0xa,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    132d <main+0x1fd>
mov    $0x0,%al
call   1050 <random@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
mov    $0x13,%ecx
cltd
idiv   %ecx
mov    %edx,-0xa4(%rbp)
movslq -0xa4(%rbp),%rax
movzbl -0xc0(%rbp,%rax,1),%eax
ff
and    $0xff,%eax
mov    %al,-0x91(%rbp)
mov    -0xa4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xa4(%rbp)
cltq
mov    -0x50(%rbp,%rax,1),%al
mov    %al,-0x51(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0xa8(%rbp)
mov    -0xa4(%rbp),%esi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0xa4(%rbp),%eax
jge    12ab <main+0x17b>
imul   $0x6d01788d,-0xa8(%rbp),%eax
78 01 6d
mov    %eax,-0xa8(%rbp)
mov    -0xa8(%rbp),%eax
add    $0x3039,%eax
mov    %eax,-0xa8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    126d <main+0x13d>
mov    -0xa8(%rbp),%eax
mov    %eax,-0xc4(%rbp)
movsbl -0x51(%rbp),%eax
xor    -0xa8(%rbp),%eax
mov    %eax,-0xa8(%rbp)
mov    -0xa8(%rbp),%eax
and    $0xff,%eax
movzbl -0x91(%rbp),%ecx
and    $0xff,%ecx
cmp    %ecx,%eax
je     12f1 <main+0x1c1>
movl   $0x0,-0x98(%rbp)
mov    -0xc4(%rbp),%eax
and    $0xff,%eax
movzbl -0x91(%rbp),%ecx
and    $0xff,%ecx
xor    %ecx,%eax
mov    %al,%cl
mov    -0xa4(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11e9 <main+0xb9>
lea    -0x90(%rbp),%rsi
lea    0xce2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
movaps 0xebd(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x78787878,0xf(%rsp)
78
movb   $0x0,0x13(%rsp)
mov    %rsp,%rdi
call   1030 <strlen@plt>
mov    $0xa,%r12d
lea    0xea7(%rip),%r14
lea    0xeb3(%rip),%r15
jmp    119d <main+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ebx,%rax
xor    (%rax,%r14,1),%bpl
mov    %bpl,(%rsp,%rax,1)
lea    -0x1(%r12),%eax
cmp    $0x1,%r12d
mov    %eax,%r12d
jbe    1226 <main+0xf6>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <random@plt>
cltq
imul   $0x6bca1af3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,8),%edx
lea    (%rcx,%rdx,2),%ecx
mov    %eax,%ebx
sub    %ecx,%ebx
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
js     1180 <main+0x50>
lea    0x1(%rbx),%ecx
mov    %ecx,%eax
and    $0x7,%eax
xor    %ebp,%ebp
cmp    $0x7,%ebx
jb     1201 <main+0xd1>
and    $0xfffffff8,%ecx
xor    %ebp,%ebp
imul   $0xba8e6421,%ebp,%ebp
add    $0x4b6e7a98,%ebp
add    $0xfffffff8,%ecx
jne    11f0 <main+0xc0>
test   %eax,%eax
je     1180 <main+0x50>
nopl   0x0(%rax)
imul   $0x6d01788d,%ebp,%ebp
add    $0x3039,%ebp
add    $0xffffffff,%eax
jne    1210 <main+0xe0>
jmp    1180 <main+0x50>
lea    0xe00(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.arr = [19 x i8] c"j\FBL\8DX\0F\D4\E8\94\98\EEk\180\E0U\C5(\0E"
@.str = [10 x i8] c"rem = %d\0A\00"
@.str.1 = [14 x i8] c"Password: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [50 x i8]
%6 = alloca i8
%7 = alloca [50 x i8]
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [19 x i8]
%16 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %9
%17 = bitcast [19 x i8]* %15 to i8*
store i32 0, i32* %2
br label %18
18: ; preds = %25, %0
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 19
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 %23
store i8 120, i8* %24
br label %25
25: ; preds = %21
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %18
28: ; preds = %18
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = icmp eq i32 %34, 19
br i1 %35, label %36, label %37
36: ; preds = %28
store i32 1, i32* %9
br label %37
37: ; preds = %36, %28
store i32 10, i32* %2
br label %38
38: ; preds = %95, %37
%39 = load i32, i32* %2
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %98
41: ; preds = %38
%42 = call i32 (...) @random()
store i32 %42, i32* %10
%43 = load i32, i32* %10
%44 = srem i32 %43, 19
store i32 %44, i32* %12
%45 = load i32, i32* %12
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [19 x i8], [19 x i8]* %15, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = and i32 %49, 255
%51 = trunc i32 %50 to i8
store i8 %51, i8* %8
%52 = load i32, i32* %12
%53 = add nsw i32 %52, 1
store i32 %53, i32* %12
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %54
%56 = load i8, i8* %55
store i8 %56, i8* %6
store i32 0, i32* %3
store i32 0, i32* %13
%57 = load i32, i32* %12
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %63, %41
%60 = load i32, i32* %3
%61 = load i32, i32* %12
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %70
63: ; preds = %59
%64 = load i32, i32* %13
%65 = mul nsw i32 %64, 1828812941
store i32 %65, i32* %13
%66 = load i32, i32* %13
%67 = add nsw i32 %66, 12345
store i32 %67, i32* %13
%68 = load i32, i32* %3
%69 = add nsw i32 %68, 1
store i32 %69, i32* %3
br label %59
70: ; preds = %59
%71 = load i32, i32* %13
store i32 %71, i32* %16
%72 = load i8, i8* %6
%73 = sext i8 %72 to i32
%74 = load i32, i32* %13
%75 = xor i32 %74, %73
store i32 %75, i32* %13
%76 = load i32, i32* %13
%77 = and i32 %76, 255
%78 = load i8, i8* %8
%79 = zext i8 %78 to i32
%80 = and i32 %79, 255
%81 = icmp ne i32 %77, %80
br i1 %81, label %82, label %83
82: ; preds = %70
store i32 0, i32* %9
br label %83
83: ; preds = %82, %70
%84 = load i32, i32* %16
%85 = and i32 %84, 255
%86 = load i8, i8* %8
%87 = zext i8 %86 to i32
%88 = and i32 %87, 255
%89 = xor i32 %85, %88
%90 = trunc i32 %89 to i8
%91 = load i32, i32* %12
%92 = sub nsw i32 %91, 1
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 %93
store i8 %90, i8* %94
br label %95
95: ; preds = %83
%96 = load i32, i32* %2
%97 = add nsw i32 %96, -1
store i32 %97, i32* %2
br label %38
98: ; preds = %38
%99 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %99)
%101 = load i32, i32* %1
ret i32 %101
}

LLVM IR (-O2):
@__const.main.arr = [19 x i8] c"j\FBL\8DX\0F\D4\E8\94\98\EEk\180\E0U\C5(\0E"
@.str = [10 x i8] c"rem = %d\0A\00"
@.str.1 = [14 x i8] c"Password: %s\0A\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 19
store i8 0, i8* %4
%5 = call i32 @strlen(i8* %3)
br label %6
6: ; preds = %0, %40
%7 = phi i32 [ 10, %0 ], [ %45, %40 ]
%8 = call i32 (...) @random()
%9 = srem i32 %8, 19
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [19 x i8], [19 x i8]* @__const.main.arr, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = add nsw i32 %9, 1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp slt i32 %9, 0
br i1 %15, label %40, label %16
16: ; preds = %6
%17 = add nsw i32 %9, 1
%18 = and i32 %17, 7
%19 = icmp ult i32 %9, 7
br i1 %19, label %29, label %20
20: ; preds = %16
%21 = and i32 %17, -8
br label %22
22: ; preds = %22, %20
%23 = phi i32 [ 0, %20 ], [ %26, %22 ]
%24 = phi i32 [ 0, %20 ], [ %27, %22 ]
%25 = mul i32 %23, -1165073375
%26 = add i32 %25, 1265531544
%27 = add i32 %24, 8
%28 = icmp eq i32 %27, %21
br i1 %28, label %29, label %22
29: ; preds = %22, %16
%30 = phi i32 [ undef, %16 ], [ %26, %22 ]
%31 = phi i32 [ 0, %16 ], [ %26, %22 ]
%32 = icmp eq i32 %18, 0
br i1 %32, label %40, label %33
33: ; preds = %29, %33
%34 = phi i32 [ %37, %33 ], [ %31, %29 ]
%35 = phi i32 [ %38, %33 ], [ 0, %29 ]
%36 = mul nsw i32 %34, 1828812941
%37 = add nsw i32 %36, 12345
%38 = add i32 %35, 1
%39 = icmp eq i32 %38, %18
br i1 %39, label %40, label %33
40: ; preds = %29, %33, %6
%41 = phi i32 [ 0, %6 ], [ %30, %29 ], [ %37, %33 ]
%42 = trunc i32 %41 to i8
%43 = xor i8 %12, %42
%44 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %10
store i8 %43, i8* %44
%45 = add nsw i32 %7, -1
%46 = icmp ugt i32 %7, 1
br i1 %46, label %6, label %47
47: ; preds = %40
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %3)
ret i32 0
}