#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, r;
  FILE *f = fopen("not.bin", "w");
  for (c = 0; c < UCHAR_MAX; c++) {
    r = ~c;
    fwrite(&r, 1, 1, f);
  }
  r = ~c;
  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    118b <main+0x6b>
movzbl -0x5(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,-0x6(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x6(%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>
movzbl -0x5(%rbp),%eax
xor    $0xffffffff,%eax
mov    %al,-0x6(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x6(%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   %rbx
push   %rax
lea    0xed2(%rip),%rdi
lea    0xed3(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%r15
mov    0x2eac(%rip),%r14
cmpb   $0x0,(%r14)
je     1170 <main+0x50>
mov    $0xff,%bpl
xor    %ebx,%ebx
nop
movsbl %bpl,%ebp
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
add    $0x1,%bl
add    $0xff,%bpl
cmp    (%r14),%bl
jb     1150 <main+0x30>
movsbl %bpl,%edi
jmp    1175 <main+0x55>
mov    $0xffffffff,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"not.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 i32*
store i32 0, i32* %1
%5 = 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* %5, i32** %4
store i8 0, i8* %2
br label %6
6: ; preds = %19, %0
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = load i8, i8* @UCHAR_MAX
%10 = zext i8 %9 to i32
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %22
12: ; preds = %6
%13 = load i8, i8* %2
%14 = zext i8 %13 to i32
%15 = xor i32 %14, -1
%16 = trunc i32 %15 to i8
store i8 %16, i8* %3
%17 = load i32*, i32** %4
%18 = call i32 @fwrite(i8* %3, i32 1, i32 1, i32* %17)
br label %19
19: ; preds = %12
%20 = load i8, i8* %2
%21 = add i8 %20, 1
store i8 %21, i8* %2
br label %6
22: ; preds = %6
%23 = load i8, i8* %2
%24 = zext i8 %23 to i32
%25 = xor i32 %24, -1
%26 = trunc i32 %25 to i8
store i8 %26, i8* %3
%27 = load i32*, i32** %4
%28 = call i32 @fwrite(i8* %3, i32 1, i32 1, i32* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"not.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 %15, label %4
4: ; preds = %0, %4
%5 = phi i8 [ %9, %4 ], [ 0, %0 ]
%6 = xor i8 %5, -1
%7 = sext i8 %6 to i32
%8 = tail call i32 @fputc(i32 %7, i32* %1)
%9 = add nuw i8 %5, 1
%10 = load i8, i8* @UCHAR_MAX
%11 = icmp ult i8 %9, %10
br i1 %11, label %4, label %12
12: ; preds = %4
%13 = sub nuw i8 -2, %5
%14 = sext i8 %13 to i32
br label %15
15: ; preds = %12, %0
%16 = phi i32 [ -1, %0 ], [ %14, %12 ]
%17 = tail call i32 @fputc(i32 %16, i32* %1)
ret i32 0
}