#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 e(char *);
int zget8();
int parse_zlib_header(void) {
  int cmf = zget8();
  int cm = cmf & 15;
  int flg = zget8();
  if ((cmf * 256 + flg) % 31 != 0)
    return e("Corrupt PNG");
  if (flg & 32)
    return e("Corrupt PNG");
  if (cm != 8)
    return e("Corrupt PNG");
  return 1;
}


x86 assembly (clang, -O0):
<parse_zlib_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <zget8@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1040 <zget8@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
add    -0x10(%rbp),%eax
mov    $0x1f,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1173 <parse_zlib_header+0x53>
lea    0xe9a(%rip),%rdi
call   1030 <e@plt>
mov    %eax,-0x4(%rbp)
jmp    11bb <parse_zlib_header+0x9b>
mov    -0x10(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1196 <parse_zlib_header+0x76>
lea    0xe77(%rip),%rdi
call   1030 <e@plt>
mov    %eax,-0x4(%rbp)
jmp    11bb <parse_zlib_header+0x9b>
cmpl   $0x8,-0xc(%rbp)
je     11b4 <parse_zlib_header+0x94>
lea    0xe59(%rip),%rdi
call   1030 <e@plt>
mov    %eax,-0x4(%rbp)
jmp    11bb <parse_zlib_header+0x9b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_zlib_header>:
push   %rbx
xor    %eax,%eax
call   1040 <zget8@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <zget8@plt>
mov    %ebx,%ecx
shl    $0x8,%ecx
add    %eax,%ecx
imul   $0xbdef7bdf,%ecx,%ecx
add    $0x4210842,%ecx
cmp    $0x8421084,%ecx
ja     1160 <parse_zlib_header+0x40>
and    $0x20,%eax
jne    1160 <parse_zlib_header+0x40>
and    $0xf,%ebx
cmp    $0x8,%ebx
jne    1160 <parse_zlib_header+0x40>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe99(%rip),%rdi
pop    %rbx
jmp    1030 <e@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Corrupt PNG\00"
define i32 @parse_zlib_header() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @zget8()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = and i32 %6, 15
store i32 %7, i32* %3
%8 = call i32 (...) @zget8()
store i32 %8, i32* %4
%9 = load i32, i32* %2
%10 = mul nsw i32 %9, 256
%11 = load i32, i32* %4
%12 = add nsw i32 %10, %11
%13 = srem i32 %12, 31
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @e(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %1
br label %29
17: ; preds = %0
%18 = load i32, i32* %4
%19 = and i32 %18, 32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @e(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %22, i32* %1
br label %29
23: ; preds = %17
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 8
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @e(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %27, i32* %1
br label %29
28: ; preds = %23
store i32 1, i32* %1
br label %29
29: ; preds = %28, %26, %21, %15
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [12 x i8] c"Corrupt PNG\00"
define i32 @parse_zlib_header() {
%1 = tail call i32 (...) @zget8()
%2 = and i32 %1, 15
%3 = tail call i32 (...) @zget8()
%4 = shl nsw i32 %1, 8
%5 = add nsw i32 %4, %3
%6 = srem i32 %5, 31
%7 = icmp eq i32 %6, 0
%8 = and i32 %3, 32
%9 = icmp eq i32 %8, 0
%10 = select i1 %7, i1 %9, i1 false
%11 = icmp eq i32 %2, 8
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = tail call i32 @e(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %0, %13
%16 = phi i32 [ %14, %13 ], [ 1, %0 ]
ret i32 %16
}