#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 */
double UINT_MAX;
double atof(char *);
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(int *, int, int, int /*<<< orphan*/);
int fwrite(int *, int, int, int /*<<< orphan*/);
int rand();
unsigned int round(double);
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "usage: glitchme <rand factor> <seed (optional int)>\n");
    return 1;
  } else {
    double fl = atof(argv[1]);
    unsigned int rf =
                     round((fl < 0.0 ? 0.0 : (fl > 1.0 ? 1.0 : fl)) * UINT_MAX),
                 r, cnt = 0;
    int nr, nw, ch;
    int seed;
    if (argc == 3) {
      seed = atoi(argv[2]);
    } else {
      seed = time(NULL);
    }
    srand((unsigned int)seed);
    nr = fread(&ch, sizeof(int), 1, stdin);
    while (nr != 0) {
      r = (unsigned int)rand();
      if (r <= rf) {
        ch ^= rand();
        nw = fwrite(&ch, sizeof(int), 1, stdout);
        cnt++;
      } else {
        nw = fwrite(&ch, sizeof(int), 1, stdout);
      }
      nr = fread(&ch, sizeof(int), 1, stdin);
    }
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d1 <main+0x41>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1350 <main+0x1c0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11fe <main+0x6e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    123b <main+0xab>
movsd  -0x18(%rbp),%xmm0
movsd  0xdf5(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1227 <main+0x97>
movsd  0xde3(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1231 <main+0xa1>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    0x2d99(%rip),%rax
mulsd  (%rax),%xmm0
call   1080 <round@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1279 <main+0xe9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x34(%rbp)
jmp    1285 <main+0xf5>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <srand@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1349 <main+0x1b9>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
ja     1306 <main+0x176>
mov    $0x0,%al
call   10b0 <rand@plt>
xor    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ce8(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1325 <main+0x195>
mov    0x2cbb(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2cbc(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x28(%rbp)
jmp    12ac <main+0x11c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11bb <main+0x2b>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    1298 <main+0x108>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1040 <atof@plt>
movsd  0xe2f(%rip),%xmm1
minsd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
cmpltsd %xmm2,%xmm0
andnpd %xmm1,%xmm0
mov    0x2df7(%rip),%rax
mulsd  (%rax),%xmm0
call   1080 <round@plt>
mov    %eax,%ebp
cmp    $0x3,%ebx
jne    1204 <main+0x74>
mov    0x10(%r14),%rdi
call   1090 <atoi@plt>
jmp    120b <main+0x7b>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    0x2dcf(%rip),%r14
mov    (%r14),%ecx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
test   %eax,%eax
je     1296 <main+0x106>
mov    0x2d8d(%rip),%r15
lea    0x4(%rsp),%rbx
jmp    127e <main+0xee>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    (%r14),%ecx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
test   %eax,%eax
je     1296 <main+0x106>
xor    %eax,%eax
call   10b0 <rand@plt>
cmp    %ebp,%eax
ja     1250 <main+0xc0>
xor    %eax,%eax
call   10b0 <rand@plt>
xor    %eax,0x4(%rsp)
jmp    1250 <main+0xc0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"usage: glitchme <rand factor> <seed (optional int)>\0A\00"
@UINT_MAX = global double 0.000000e+00
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %77
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call double @atof(i8* %22)
store double %23, double* %6
%24 = load double, double* %6
%25 = fcmp olt double %24, 0.000000e+00
br i1 %25, label %26, label %27
26: ; preds = %19
br label %35
27: ; preds = %19
%28 = load double, double* %6
%29 = fcmp ogt double %28, 1.000000e+00
br i1 %29, label %30, label %31
30: ; preds = %27
br label %33
31: ; preds = %27
%32 = load double, double* %6
br label %33
33: ; preds = %31, %30
%34 = phi double [ 1.000000e+00, %30 ], [ %32, %31 ]
br label %35
35: ; preds = %33, %26
%36 = phi double [ 0.000000e+00, %26 ], [ %34, %33 ]
%37 = load double, double* @UINT_MAX
%38 = fmul double %36, %37
%39 = call i32 @round(double %38)
store i32 %39, i32* %7
store i32 0, i32* %9
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 3
br i1 %41, label %42, label %47
42: ; preds = %35
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %13
br label %49
47: ; preds = %35
%48 = call i32 @time(i32* null)
store i32 %48, i32* %13
br label %49
49: ; preds = %47, %42
%50 = load i32, i32* %13
%51 = call i32 @srand(i32 %50)
%52 = load i32, i32* @stdin
%53 = call i32 @fread(i32* %12, i32 4, i32 1, i32 %52)
store i32 %53, i32* %10
br label %54
54: ; preds = %73, %49
%55 = load i32, i32* %10
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %76
57: ; preds = %54
%58 = call i32 (...) @rand()
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = load i32, i32* %7
%61 = icmp ule i32 %59, %60
br i1 %61, label %62, label %70
62: ; preds = %57
%63 = call i32 (...) @rand()
%64 = load i32, i32* %12
%65 = xor i32 %64, %63
store i32 %65, i32* %12
%66 = load i32, i32* @stdout
%67 = call i32 @fwrite(i32* %12, i32 4, i32 1, i32 %66)
store i32 %67, i32* %11
%68 = load i32, i32* %9
%69 = add i32 %68, 1
store i32 %69, i32* %9
br label %73
70: ; preds = %57
%71 = load i32, i32* @stdout
%72 = call i32 @fwrite(i32* %12, i32 4, i32 1, i32 %71)
store i32 %72, i32* %11
br label %73
73: ; preds = %70, %62
%74 = load i32, i32* @stdin
%75 = call i32 @fread(i32* %12, i32 4, i32 1, i32 %74)
store i32 %75, i32* %10
br label %54
76: ; preds = %54
store i32 0, i32* %3
br label %77
77: ; preds = %76, %16
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"usage: glitchme <rand factor> <seed (optional int)>\0A\00"
@UINT_MAX = global double 0.000000e+00
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
br label %47
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call double @atof(i8* %10)
%12 = fcmp olt double %11, 0.000000e+00
%13 = fcmp ogt double %11, 1.000000e+00
%14 = select i1 %13, double 1.000000e+00, double %11
%15 = select i1 %12, double 0.000000e+00, double %14
%16 = load double, double* @UINT_MAX
%17 = fmul double %16, %15
%18 = tail call i32 @round(double %17)
%19 = bitcast i32* %3 to i8*
%20 = icmp eq i32 %0, 3
br i1 %20, label %21, label %25
21: ; preds = %8
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
br label %27
25: ; preds = %8
%26 = tail call i32 @time(i32* null)
br label %27
27: ; preds = %25, %21
%28 = phi i32 [ %24, %21 ], [ %26, %25 ]
%29 = tail call i32 @srand(i32 %28)
%30 = load i32, i32* @stdin
%31 = call i32 @fread(i32* %3, i32 4, i32 1, i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %46, label %33
33: ; preds = %27, %40
%34 = call i32 (...) @rand()
%35 = icmp ugt i32 %34, %18
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = call i32 (...) @rand()
%38 = load i32, i32* %3
%39 = xor i32 %38, %37
store i32 %39, i32* %3
br label %40
40: ; preds = %33, %36
%41 = load i32, i32* @stdout
%42 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32 %41)
%43 = load i32, i32* @stdin
%44 = call i32 @fread(i32* %3, i32 4, i32 1, i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %33
46: ; preds = %40, %27
br label %47
47: ; preds = %46, %5
%48 = phi i32 [ 1, %5 ], [ 0, %46 ]
ret i32 %48
}