#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned char UCHAR_MAX;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int main(void) {
  unsigned char c, x, r;
  FILE *f = fopen("and.bin", "w");
  for (c = 0; c < UCHAR_MAX; c++) {
    for (x = 0; x < UCHAR_MAX; x++) {
      r = c & x;
      fwrite(&r, 1, 1, f);
    }
    r = c & x;
    fwrite(&r, 1, 1, f);
  }
  for (x = 0; x < UCHAR_MAX; x++) {
    r = c & x;
    fwrite(&r, 1, 1, f);
  }
  r = c & x;
  fwrite(&r, 1, 1, f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    0xecb(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
mov    0x2e9b(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jge    11d6 <main+0xb6>
movb   $0x0,-0x6(%rbp)
movzbl -0x6(%rbp),%eax
mov    0x2e81(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jge    11a8 <main+0x88>
movzbl -0x5(%rbp),%eax
movzbl -0x6(%rbp),%ecx
and    %ecx,%eax
mov    %al,-0x7(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x7(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite@plt>
mov    -0x6(%rbp),%al
add    $0x1,%al
mov    %al,-0x6(%rbp)
jmp    1164 <main+0x44>
movzbl -0x5(%rbp),%eax
movzbl -0x6(%rbp),%ecx
and    %ecx,%eax
mov    %al,-0x7(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x7(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite@plt>
mov    -0x5(%rbp),%al
add    $0x1,%al
mov    %al,-0x5(%rbp)
jmp    114a <main+0x2a>
movb   $0x0,-0x6(%rbp)
movzbl -0x6(%rbp),%eax
mov    0x2e0b(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jge    121e <main+0xfe>
movzbl -0x5(%rbp),%eax
movzbl -0x6(%rbp),%ecx
and    %ecx,%eax
mov    %al,-0x7(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x7(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite@plt>
mov    -0x6(%rbp),%al
add    $0x1,%al
mov    %al,-0x6(%rbp)
jmp    11da <main+0xba>
movzbl -0x5(%rbp),%eax
movzbl -0x6(%rbp),%ecx
and    %ecx,%eax
mov    %al,-0x7(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x7(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fwrite@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xed1(%rip),%rdi
lea    0xed2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r12
mov    0x2eab(%rip),%r14
cmpb   $0x0,(%r14)
je     11bc <main+0x9c>
xor    %ebp,%ebp
nopl   (%rax)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
and    %bpl,%al
movsbl %al,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
add    $0x1,%bl
cmp    (%r14),%bl
jb     1160 <main+0x40>
and    %bpl,%bl
movsbl %bl,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
add    $0x1,%bpl
mov    (%r14),%al
cmp    %al,%bpl
jb     1150 <main+0x30>
xor    %r15d,%r15d
test   %al,%al
je     11c1 <main+0xa1>
nopl   0x0(%rax)
mov    %r15d,%eax
and    %bpl,%al
movsbl %al,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
add    $0x1,%r15b
cmp    (%r14),%r15b
jb     11a0 <main+0x80>
jmp    11c1 <main+0xa1>
xor    %ebp,%ebp
xor    %r15d,%r15d
and    %r15b,%bpl
movsbl %bpl,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"and.bin\00"
@.str.1 = [2 x i8] c"w\00"
@UCHAR_MAX = global i8 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = load i8, i8* @UCHAR_MAX
%3 = icmp eq i8 %2, 0
br i1 %3, label %31, label %4
4: ; preds = %0, %16
%5 = phi i8 [ %20, %16 ], [ 0, %0 ]
br label %8
6: ; preds = %16
%7 = icmp eq i8 %21, 0
br i1 %7, label %31, label %23
8: ; preds = %4, %8
%9 = phi i8 [ %13, %8 ], [ 0, %4 ]
%10 = and i8 %9, %5
%11 = sext i8 %10 to i32
%12 = tail call i32 @fputc(i32 %11, i32* %1)
%13 = add nuw i8 %9, 1
%14 = load i8, i8* @UCHAR_MAX
%15 = icmp ult i8 %13, %14
br i1 %15, label %8, label %16
16: ; preds = %8
%17 = and i8 %13, %5
%18 = sext i8 %17 to i32
%19 = tail call i32 @fputc(i32 %18, i32* %1)
%20 = add nuw i8 %5, 1
%21 = load i8, i8* @UCHAR_MAX
%22 = icmp ult i8 %20, %21
br i1 %22, label %4, label %6
23: ; preds = %6, %23
%24 = phi i8 [ %28, %23 ], [ 0, %6 ]
%25 = and i8 %24, %20
%26 = sext i8 %25 to i32
%27 = tail call i32 @fputc(i32 %26, i32* %1)
%28 = add nuw i8 %24, 1
%29 = load i8, i8* @UCHAR_MAX
%30 = icmp ult i8 %28, %29
br i1 %30, label %23, label %31
31: ; preds = %23, %0, %6
%32 = phi i8 [ %20, %6 ], [ 0, %0 ], [ %20, %23 ]
%33 = phi i8 [ 0, %6 ], [ 0, %0 ], [ %28, %23 ]
%34 = and i8 %33, %32
%35 = sext i8 %34 to i32
%36 = tail call i32 @fputc(i32 %35, i32* %1)
ret i32 0
}