#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 */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void printJpegStream(FILE *f) {
  int c, l;
  while (!feof(f)) {
    if (fgetc(f) != 0xFF) {
      printf("Jpeg marker not found!\n");
      break;
    }
    switch (c = fgetc(f)) {
    case 0xD8:
      printf("SOI\n");
      break;
    case 0xD9:
      printf("EOI\n");
      break;
    case 0xE0:
      printf("JFIF\n");
      break;
    case 0xDB:
      printf("Quantization table\n");
      break;
    case 0xC4:
      printf("Huffman table\n");
      break;
    case 0xC0:
      printf("Start of frame 0\n");
      break;
    case 0xC1:
      printf("Start of frame 1\n");
      break;
    case 0xC2:
      printf("Start of frame 2\n");
      break;
    case 0xDA:
      printf("Start of scan\n");
      break;
    default:
      printf("Unknown JPEG block: %02x\n", c);
    }
    if (c == 0xDA)
      break;
    if (c != 0xD8 && c != 0xD9) {
      l = (fgetc(f) << 8) + fgetc(f);
      printf("%i bytes\n", l);
      for (l -= 2; l > 0; --l)
        fgetc(f);
    }
  }
}


x86 assembly (clang, -O0):
<printJpegStream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    115a <printJpegStream+0x2a>
jmp    1304 <printJpegStream+0x1d4>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
cmp    $0xff,%eax
je     1181 <printJpegStream+0x51>
lea    0xf0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1304 <printJpegStream+0x1d4>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0xc(%rbp)
add    $0xffffff40,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x20,%eax
ja     1260 <printJpegStream+0x130>
mov    -0x18(%rbp),%rax
lea    0xe54(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <printJpegStream+0x141>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <printJpegStream+0x141>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <printJpegStream+0x141>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <printJpegStream+0x141>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <printJpegStream+0x141>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <printJpegStream+0x141>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <printJpegStream+0x141>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <printJpegStream+0x141>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <printJpegStream+0x141>
mov    -0xc(%rbp),%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xda,-0xc(%rbp)
jne    1283 <printJpegStream+0x153>
jmp    1304 <printJpegStream+0x1d4>
cmpl   $0xd8,-0xc(%rbp)
je     12ff <printJpegStream+0x1cf>
cmpl   $0xd9,-0xc(%rbp)
je     12ff <printJpegStream+0x1cf>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
shl    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    12fa <printJpegStream+0x1ca>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    12d9 <printJpegStream+0x1a9>
jmp    12ff <printJpegStream+0x1cf>
jmp    113c <printJpegStream+0xc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printJpegStream>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <feof@plt>
test   %eax,%eax
je     1166 <printJpegStream+0x26>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xf3b(%rip),%rax
mov    %rax,(%rsp)
lea    0xf9b(%rip),%r12
lea    0xe81(%rip),%r14
jmp    119c <printJpegStream+0x5c>
lea    0xf87(%rip),%rax
mov    %rax,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1157 <printJpegStream+0x17>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0xff,%eax
jne    1295 <printJpegStream+0x155>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r13d
lea    -0xc0(%r13),%eax
cmp    $0x20,%eax
ja     11f4 <printJpegStream+0xb4>
movslq (%r14,%rax,4),%rcx
add    %r14,%rcx
lea    0xf36(%rip),%rdi
mov    %r12,%rax
jmp    *%rcx
lea    0xef8(%rip),%rdi
jmp    1230 <printJpegStream+0xf0>
lea    0xede(%rip),%rdi
jmp    1230 <printJpegStream+0xf0>
lea    0xec4(%rip),%rdi
jmp    1230 <printJpegStream+0xf0>
lea    0xe89(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
and    $0xfffffffe,%r13d
cmp    $0xd8,%r13d
je     1190 <printJpegStream+0x50>
jmp    1235 <printJpegStream+0xf5>
lea    0xeca(%rip),%rdi
jmp    1230 <printJpegStream+0xf0>
lea    0xecf(%rip),%rdi
nopl   0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r13d
shl    $0x8,%r13d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
lea    0x0(%r13,%rbp,1),%r15d
lea    0xe44(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x3,%r15d
jl     1190 <printJpegStream+0x50>
add    %r13d,%ebp
add    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <fgetc@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1280 <printJpegStream+0x140>
jmp    1190 <printJpegStream+0x50>
lea    0xe7b(%rip),%rax
mov    %rax,(%rsp)
mov    (%rsp),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Jpeg marker not found!\0A\00"
@.str.1 = [5 x i8] c"SOI\0A\00"
@.str.2 = [5 x i8] c"EOI\0A\00"
@.str.3 = [6 x i8] c"JFIF\0A\00"
@.str.4 = [20 x i8] c"Quantization table\0A\00"
@.str.5 = [15 x i8] c"Huffman table\0A\00"
@.str.6 = [18 x i8] c"Start of frame 0\0A\00"
@.str.7 = [18 x i8] c"Start of frame 1\0A\00"
@.str.8 = [18 x i8] c"Start of frame 2\0A\00"
@.str.9 = [15 x i8] c"Start of scan\0A\00"
@.str.10 = [26 x i8] c"Unknown JPEG block: %02x\0A\00"
@.str.11 = [10 x i8] c"%i bytes\0A\00"
define void @printJpegStream(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
br label %5
5: ; preds = %71, %1
%6 = load i32*, i32** %2
%7 = call i32 @feof(i32* %6)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %72
10: ; preds = %5
%11 = load i32*, i32** %2
%12 = call i32 @fgetc(i32* %11)
%13 = icmp ne i32 %12, 255
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %72
16: ; preds = %10
%17 = load i32*, i32** %2
%18 = call i32 @fgetc(i32* %17)
store i32 %18, i32* %3
switch i32 %18, label %37 [
i32 216, label %19
i32 217, label %21
i32 224, label %23
i32 219, label %25
i32 196, label %27
i32 192, label %29
i32 193, label %31
i32 194, label %33
i32 218, label %35
]
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %40
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %40
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %40
25: ; preds = %16
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %40
27: ; preds = %16
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %40
29: ; preds = %16
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %40
31: ; preds = %16
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %40
33: ; preds = %16
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %40
35: ; preds = %16
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %40
37: ; preds = %16
%38 = load i32, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %37, %35, %33, %31, %29, %27, %25, %23, %21, %19
%41 = load i32, i32* %3
%42 = icmp eq i32 %41, 218
br i1 %42, label %43, label %44
43: ; preds = %40
br label %72
44: ; preds = %40
%45 = load i32, i32* %3
%46 = icmp ne i32 %45, 216
br i1 %46, label %47, label %71
47: ; preds = %44
%48 = load i32, i32* %3
%49 = icmp ne i32 %48, 217
br i1 %49, label %50, label %71
50: ; preds = %47
%51 = load i32*, i32** %2
%52 = call i32 @fgetc(i32* %51)
%53 = shl i32 %52, 8
%54 = load i32*, i32** %2
%55 = call i32 @fgetc(i32* %54)
%56 = add nsw i32 %53, %55
store i32 %56, i32* %4
%57 = load i32, i32* %4
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %4
%60 = sub nsw i32 %59, 2
store i32 %60, i32* %4
br label %61
61: ; preds = %67, %50
%62 = load i32, i32* %4
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %61
%65 = load i32*, i32** %2
%66 = call i32 @fgetc(i32* %65)
br label %67
67: ; preds = %64
%68 = load i32, i32* %4
%69 = add nsw i32 %68, -1
store i32 %69, i32* %4
br label %61
70: ; preds = %61
br label %71
71: ; preds = %70, %47, %44
br label %5
72: ; preds = %43, %14, %5
ret void
}

LLVM IR (-O2):
@.str.10 = [26 x i8] c"Unknown JPEG block: %02x\0A\00"
@.str.11 = [10 x i8] c"%i bytes\0A\00"
@str = [14 x i8] c"Start of scan\00"
@str.12 = [17 x i8] c"Start of frame 2\00"
@str.13 = [17 x i8] c"Start of frame 1\00"
@str.14 = [17 x i8] c"Start of frame 0\00"
@str.15 = [14 x i8] c"Huffman table\00"
@str.16 = [19 x i8] c"Quantization table\00"
@str.17 = [5 x i8] c"JFIF\00"
@str.18 = [4 x i8] c"EOI\00"
@str.19 = [4 x i8] c"SOI\00"
@str.20 = [23 x i8] c"Jpeg marker not found!\00"
define void @printJpegStream(i32* nocapture %0) {
%2 = tail call i32 @feof(i32* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %45
4: ; preds = %1, %39
%5 = tail call i32 @fgetc(i32* %0)
%6 = icmp eq i32 %5, 255
br i1 %6, label %7, label %42
7: ; preds = %4
%8 = tail call i32 @fgetc(i32* %0)
switch i32 %8, label %15 [
i32 216, label %36
i32 217, label %9
i32 224, label %19
i32 219, label %10
i32 196, label %11
i32 192, label %12
i32 193, label %13
i32 194, label %14
i32 218, label %42
]
9: ; preds = %7
br label %36
10: ; preds = %7
br label %19
11: ; preds = %7
br label %19
12: ; preds = %7
br label %19
13: ; preds = %7
br label %19
14: ; preds = %7
br label %19
15: ; preds = %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i32 %8)
%17 = and i32 %8, -2
%18 = icmp eq i32 %17, 216
br i1 %18, label %39, label %22
19: ; preds = %7, %14, %13, %12, %11, %10
%20 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.16, i64 0, i64 0), %10 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.15, i64 0, i64 0), %11 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.14, i64 0, i64 0), %12 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.13, i64 0, i64 0), %13 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.12, i64 0, i64 0), %14 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.17, i64 0, i64 0), %7 ]
%21 = tail call i32 @puts(i8* dereferenceable(1) %20)
br label %22
22: ; preds = %19, %15
%23 = tail call i32 @fgetc(i32* %0)
%24 = shl i32 %23, 8
%25 = tail call i32 @fgetc(i32* %0)
%26 = add nsw i32 %24, %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i32 %26)
%28 = icmp sgt i32 %26, 2
br i1 %28, label %29, label %39
29: ; preds = %22
%30 = add nsw i32 %26, -2
br label %31
31: ; preds = %29, %31
%32 = phi i32 [ %34, %31 ], [ %30, %29 ]
%33 = tail call i32 @fgetc(i32* %0)
%34 = add nsw i32 %32, -1
%35 = icmp ugt i32 %32, 1
br i1 %35, label %31, label %39
36: ; preds = %7, %9
%37 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.18, i64 0, i64 0), %9 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.19, i64 0, i64 0), %7 ]
%38 = tail call i32 @puts(i8* dereferenceable(1) %37)
br label %39
39: ; preds = %31, %36, %22, %15
%40 = tail call i32 @feof(i32* %0)
%41 = icmp eq i32 %40, 0
br i1 %41, label %4, label %45
42: ; preds = %7, %4
%43 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.20, i64 0, i64 0), %4 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0), %7 ]
%44 = tail call i32 @puts(i8* dereferenceable(1) %43)
br label %45
45: ; preds = %39, %42, %1
ret void
}