#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*/ SEEK_CUR;
int /*<<< orphan*/ copy_rest(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fail(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
void skip_jfif(FILE *f, FILE *g) {
  int a, b;
  a = getc(f);
  b = getc(f);
  if (a != 0xFF || b != 0xD8)
    fail("not a JPEG file");
  putc(a, g);
  putc(b, g);
  while (a = getc(f), b = getc(f), a == 0xFF && b == 0xE0) {
    a = getc(f);
    b = getc(f);
    if (a == 0xEF || b == 0xEF)
      fail("stop confusing me with weird test cases");
    fseek(f, a * 256 + b - 2, SEEK_CUR);
  }
  if (a != 0xEF)
    putc(a, g);
  if (b != 0xEF)
    putc(b, g);
  copy_rest(f, g);
}


x86 assembly (clang, -O0):
<skip_jfif>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xff,-0x14(%rbp)
jne    1192 <skip_jfif+0x42>
cmpl   $0xd8,-0x18(%rbp)
je     119e <skip_jfif+0x4e>
lea    0xe67(%rip),%rdi
call   1040 <fail@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <putc@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <putc@plt>
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0xff,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jne    11ed <skip_jfif+0x9d>
cmpl   $0xe0,-0x18(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11fd <skip_jfif+0xad>
jmp    125e <skip_jfif+0x10e>
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xef,-0x14(%rbp)
je     122f <skip_jfif+0xdf>
cmpl   $0xef,-0x18(%rbp)
jne    123b <skip_jfif+0xeb>
lea    0xdda(%rip),%rdi
call   1040 <fail@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
shl    $0x8,%esi
add    -0x18(%rbp),%esi
sub    $0x2,%esi
mov    0x2d96(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
jmp    11b6 <skip_jfif+0x66>
cmpl   $0xef,-0x14(%rbp)
je     1277 <skip_jfif+0x127>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <putc@plt>
cmpl   $0xef,-0x18(%rbp)
je     1290 <skip_jfif+0x140>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <putc@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <copy_rest@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_jfif>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    $0xff,%ebx
jne    1182 <skip_jfif+0x32>
cmp    $0xd8,%ebp
je     118e <skip_jfif+0x3e>
lea    0xe77(%rip),%rdi
call   1040 <fail@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <putc@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <putc@plt>
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %eax,%ebx
cmp    $0xff,%ebp
jne    1245 <skip_jfif+0xf5>
cmp    $0xe0,%ebx
jne    1245 <skip_jfif+0xf5>
lea    0xe3f(%rip),%r15
mov    0x2e10(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    $0xef,%ebx
je     1204 <skip_jfif+0xb4>
cmp    $0xef,%ebp
jne    120c <skip_jfif+0xbc>
mov    %r15,%rdi
call   1040 <fail@plt>
shl    $0x8,%ebx
lea    (%rbx,%rbp,1),%esi
add    $0xfffffffe,%esi
mov    0x0(%r13),%edx
mov    %r12,%rdi
call   1060 <fseek@plt>
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %eax,%ebx
cmp    $0xff,%ebp
jne    1245 <skip_jfif+0xf5>
cmp    $0xe0,%ebx
je     11e0 <skip_jfif+0x90>
cmp    $0xef,%ebp
je     1257 <skip_jfif+0x107>
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <putc@plt>
cmp    $0xef,%ebx
je     1269 <skip_jfif+0x119>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <putc@plt>
mov    %r12,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <copy_rest@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"not a JPEG file\00"
@.str.1 = [40 x i8] c"stop confusing me with weird test cases\00"
@SEEK_CUR = global i32 0
define void @skip_jfif(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %3
%8 = call i32 @getc(i32* %7)
store i32 %8, i32* %5
%9 = load i32*, i32** %3
%10 = call i32 @getc(i32* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 255
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 216
br i1 %15, label %16, label %18
16: ; preds = %13, %2
%17 = call i32 @fail(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %5
%20 = load i32*, i32** %4
%21 = call i32 @putc(i32 %19, i32* %20)
%22 = load i32, i32* %6
%23 = load i32*, i32** %4
%24 = call i32 @putc(i32 %22, i32* %23)
br label %25
25: ; preds = %49, %18
%26 = load i32*, i32** %3
%27 = call i32 @getc(i32* %26)
store i32 %27, i32* %5
%28 = load i32*, i32** %3
%29 = call i32 @getc(i32* %28)
store i32 %29, i32* %6
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 255
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 224
br label %35
35: ; preds = %32, %25
%36 = phi i1 [ false, %25 ], [ %34, %32 ]
br i1 %36, label %37, label %58
37: ; preds = %35
%38 = load i32*, i32** %3
%39 = call i32 @getc(i32* %38)
store i32 %39, i32* %5
%40 = load i32*, i32** %3
%41 = call i32 @getc(i32* %40)
store i32 %41, i32* %6
%42 = load i32, i32* %5
%43 = icmp eq i32 %42, 239
br i1 %43, label %47, label %44
44: ; preds = %37
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 239
br i1 %46, label %47, label %49
47: ; preds = %44, %37
%48 = call i32 @fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
%50 = load i32*, i32** %3
%51 = load i32, i32* %5
%52 = mul nsw i32 %51, 256
%53 = load i32, i32* %6
%54 = add nsw i32 %52, %53
%55 = sub nsw i32 %54, 2
%56 = load i32, i32* @SEEK_CUR
%57 = call i32 @fseek(i32* %50, i32 %55, i32 %56)
br label %25
58: ; preds = %35
%59 = load i32, i32* %5
%60 = icmp ne i32 %59, 239
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = load i32, i32* %5
%63 = load i32*, i32** %4
%64 = call i32 @putc(i32 %62, i32* %63)
br label %65
65: ; preds = %61, %58
%66 = load i32, i32* %6
%67 = icmp ne i32 %66, 239
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = load i32, i32* %6
%70 = load i32*, i32** %4
%71 = call i32 @putc(i32 %69, i32* %70)
br label %72
72: ; preds = %68, %65
%73 = load i32*, i32** %3
%74 = load i32*, i32** %4
%75 = call i32 @copy_rest(i32* %73, i32* %74)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"not a JPEG file\00"
@.str.1 = [40 x i8] c"stop confusing me with weird test cases\00"
@SEEK_CUR = global i32 0
define void @skip_jfif(i32* %0, i32* %1) {
%3 = tail call i32 @getc(i32* %0)
%4 = tail call i32 @getc(i32* %0)
%5 = icmp ne i32 %3, 255
%6 = icmp ne i32 %4, 216
%7 = or i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @fail(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %2, %8
%11 = tail call i32 @putc(i32 %3, i32* %1)
%12 = tail call i32 @putc(i32 %4, i32* %1)
%13 = tail call i32 @getc(i32* %0)
%14 = tail call i32 @getc(i32* %0)
%15 = icmp eq i32 %13, 255
%16 = icmp eq i32 %14, 224
%17 = and i1 %15, %16
br i1 %17, label %18, label %37
18: ; preds = %10, %26
%19 = tail call i32 @getc(i32* %0)
%20 = tail call i32 @getc(i32* %0)
%21 = icmp eq i32 %19, 239
%22 = icmp eq i32 %20, 239
%23 = or i1 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = tail call i32 @fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %18, %24
%27 = shl nsw i32 %19, 8
%28 = add i32 %20, -2
%29 = add i32 %28, %27
%30 = load i32, i32* @SEEK_CUR
%31 = tail call i32 @fseek(i32* %0, i32 %29, i32 %30)
%32 = tail call i32 @getc(i32* %0)
%33 = tail call i32 @getc(i32* %0)
%34 = icmp eq i32 %32, 255
%35 = icmp eq i32 %33, 224
%36 = and i1 %34, %35
br i1 %36, label %18, label %37
37: ; preds = %26, %10
%38 = phi i32 [ %13, %10 ], [ %32, %26 ]
%39 = phi i32 [ %14, %10 ], [ %33, %26 ]
%40 = icmp eq i32 %38, 239
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = tail call i32 @putc(i32 %38, i32* %1)
br label %43
43: ; preds = %41, %37
%44 = icmp eq i32 %39, 239
br i1 %44, label %47, label %45
45: ; preds = %43
%46 = tail call i32 @putc(i32 %39, i32* %1)
br label %47
47: ; preds = %45, %43
%48 = tail call i32 @copy_rest(i32* %0, i32* %1)
ret void
}