#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, unsigned char, int);
int read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned char buf[512];
  unsigned char n = 0;
  int c;
  if (read(0, buf, 512) != 512) {
    fprintf(stderr, "Wrong size\n");
    exit(1);
  }
  for (c = 0x0; c < 0x1ff; c++)
    n += buf[c];
  printf("Checksum byte is %02x, should be %02x\n", buf[0x1ff], 0xff - n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x211(%rbp)
lea    -0x210(%rbp),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1040 <read@plt>
cmp    $0x200,%eax
je     119d <main+0x5d>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x218(%rbp)
cmpl   $0x1ff,-0x218(%rbp)
jge    11e9 <main+0xa9>
movslq -0x218(%rbp),%rax
movzbl -0x210(%rbp,%rax,1),%ecx
ff
movzbl -0x211(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x211(%rbp)
mov    -0x218(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x218(%rbp)
jmp    11a7 <main+0x67>
mov    -0x11(%rbp),%al
movzbl -0x211(%rbp),%ecx
mov    $0xff,%edx
sub    %ecx,%edx
lea    0xe0b(%rip),%rdi
movzbl %al,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x200,%rsp
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1040 <read@plt>
cmp    $0x200,%eax
jne    11c0 <main+0x80>
mov    $0x3,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movzbl -0x3(%rsp,%rax,1),%ecx
add    %ebx,%ecx
movzbl -0x2(%rsp,%rax,1),%edx
add    %ecx,%edx
movzbl -0x1(%rsp,%rax,1),%ecx
add    %edx,%ecx
cmp    $0x1ff,%rax
je     119c <main+0x5c>
movzbl (%rsp,%rax,1),%edx
add    %edx,%ecx
movzbl %cl,%ebx
add    $0x4,%rax
jmp    1170 <main+0x30>
not    %ecx
movzbl 0x1ff(%rsp),%esi
movzbl %cl,%edx
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
ret
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"Wrong size\0A\00"
@.str.1 = [39 x i8] c"Checksum byte is %02x, should be %02x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i8
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %7
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%10 = call i32 @read(i32 0, i8* %9, i32 512)
%11 = icmp ne i32 %10, 512
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
store i32 0, i32* %8
br label %17
17: ; preds = %30, %16
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 511
br i1 %19, label %20, label %33
20: ; preds = %17
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = load i8, i8* %7
%27 = zext i8 %26 to i32
%28 = add nsw i32 %27, %25
%29 = trunc i32 %28 to i8
store i8 %29, i8* %7
br label %30
30: ; preds = %20
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %17
33: ; preds = %17
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 511
%35 = load i8, i8* %34
%36 = load i8, i8* %7
%37 = zext i8 %36 to i32
%38 = sub nsw i32 255, %37
%39 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %35, i32 %38)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"Wrong size\0A\00"
@.str.1 = [39 x i8] c"Checksum byte is %02x, should be %02x\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 512)
%6 = icmp eq i32 %5, 512
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2, %30
%12 = phi i64 [ %35, %30 ], [ 0, %2 ]
%13 = phi i32 [ %36, %30 ], [ 0, %2 ]
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %12
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = add nuw nsw i32 %13, %16
%18 = or i64 %12, 1
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = add nuw nsw i32 %17, %21
%23 = or i64 %12, 2
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = add nuw nsw i32 %22, %26
%28 = or i64 %12, 3
%29 = icmp eq i64 %28, 511
br i1 %29, label %37, label %30
30: ; preds = %11
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %28
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = add nuw nsw i32 %27, %33
%35 = add nuw nsw i64 %12, 4
%36 = and i32 %34, 255
br label %11
37: ; preds = %11
%38 = and i32 %27, 255
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 511
%40 = load i8, i8* %39
%41 = xor i32 %38, 255
%42 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %40, i32 %41)
ret i32 0
}