#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 */
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc2LowHigh(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc4LowHigh(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int putBmpHeader(FILE *s, int x, int y, int c) {
  int i;
  int color;
  unsigned long int bfOffBits;
  if (x <= 0 || y <= 0) {
    return 0;
  }
  if (s == NULL || ferror(s)) {
    return 0;
  }
  if (c == 24) {
    color = 0;
  } else {
    color = 1;
    for (i = 1; i <= c; i++) {
      color *= 2;
    }
  }
  bfOffBits = 14 + 40 + 4 * color;
  fputs("BM", s);
  fputc4LowHigh(bfOffBits + (unsigned long)x * y, s);
  fputc2LowHigh(0, s);
  fputc2LowHigh(0, s);
  fputc4LowHigh(bfOffBits, s);
  fputc4LowHigh(40, s);
  fputc4LowHigh(x, s);
  fputc4LowHigh(y, s);
  fputc2LowHigh(1, s);
  fputc2LowHigh(c, s);
  fputc4LowHigh(0, s);
  fputc4LowHigh(0, s);
  fputc4LowHigh(0, s);
  fputc4LowHigh(0, s);
  fputc4LowHigh(0, s);
  fputc4LowHigh(0, s);
  if (ferror(s)) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<putBmpHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1169 <putBmpHeader+0x29>
cmpl   $0x0,-0x18(%rbp)
jg     1175 <putBmpHeader+0x35>
movl   $0x0,-0x4(%rbp)
jmp    12f5 <putBmpHeader+0x1b5>
cmpq   $0x0,-0x10(%rbp)
je     1193 <putBmpHeader+0x53>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     119f <putBmpHeader+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    12f5 <putBmpHeader+0x1b5>
cmpl   $0x18,-0x1c(%rbp)
jne    11b5 <putBmpHeader+0x75>
movl   $0x0,-0x24(%rbp)
jmp    11eb <putBmpHeader+0xab>
movl   $0x1,-0x24(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11e6 <putBmpHeader+0xa6>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c3 <putBmpHeader+0x83>
jmp    11eb <putBmpHeader+0xab>
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
add    $0x36,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xdfb(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movslq -0x18(%rbp),%rdx
imul   %rdx,%rcx
add    %rcx,%rax
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc4LowHigh@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1060 <fputc2LowHigh@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1060 <fputc2LowHigh@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc4LowHigh@plt>
mov    -0x10(%rbp),%rsi
mov    $0x28,%edi
call   1040 <fputc4LowHigh@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc4LowHigh@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc4LowHigh@plt>
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
call   1060 <fputc2LowHigh@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <fputc2LowHigh@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc4LowHigh@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc4LowHigh@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc4LowHigh@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc4LowHigh@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc4LowHigh@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc4LowHigh@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12ee <putBmpHeader+0x1ae>
movl   $0x0,-0x4(%rbp)
jmp    12f5 <putBmpHeader+0x1b5>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putBmpHeader>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     12c4 <putBmpHeader+0x184>
mov    %esi,%r13d
test   %esi,%esi
jle    12c4 <putBmpHeader+0x184>
mov    %edx,%r15d
test   %edx,%edx
jle    12c4 <putBmpHeader+0x184>
mov    %ecx,%r14d
mov    %rdi,%rbx
call   1030 <ferror@plt>
test   %rax,%rax
jne    12c4 <putBmpHeader+0x184>
mov    $0x36,%r12d
cmp    $0x18,%r14d
je     11f2 <putBmpHeader+0xb2>
test   %r14d,%r14d
jle    11a7 <putBmpHeader+0x67>
lea    -0x1(%r14),%ecx
mov    %r14d,%eax
and    $0x7,%eax
cmp    $0x7,%ecx
jae    11af <putBmpHeader+0x6f>
mov    $0x1,%ecx
jmp    11cd <putBmpHeader+0x8d>
mov    $0x3a,%r12d
jmp    11f2 <putBmpHeader+0xb2>
mov    %r14d,%esi
and    $0xfffffff8,%esi
mov    $0x1,%ecx
nopw   0x0(%rax,%rax,1)
mov    %ecx,%edx
shl    $0x8,%ecx
add    $0xfffffff8,%esi
jne    11c0 <putBmpHeader+0x80>
shl    $0x7,%edx
test   %eax,%eax
je     11ea <putBmpHeader+0xaa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edx
lea    (%rdx,%rdx,1),%ecx
add    $0xffffffff,%eax
jne    11e0 <putBmpHeader+0xa0>
lea    0x36(,%rdx,8),%r12d
lea    0xe07(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    %r15d,%edi
imul   %r13d,%edi
add    %r12d,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc2LowHigh@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <fputc2LowHigh@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
mov    $0x28,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1050 <fputc2LowHigh@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <fputc2LowHigh@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc4LowHigh@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"BM\00"
define i32 @putBmpHeader(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* %7
%14 = icmp sle i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %4
%16 = load i32, i32* %8
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15, %4
store i32 0, i32* %5
br label %98
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = load i32*, i32** %6
%24 = call i64 @ferror(i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22, %19
store i32 0, i32* %5
br label %98
27: ; preds = %22
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, 24
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 0, i32* %11
br label %43
31: ; preds = %27
store i32 1, i32* %11
store i32 1, i32* %10
br label %32
32: ; preds = %39, %31
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = icmp sle i32 %33, %34
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i32, i32* %11
%38 = mul nsw i32 %37, 2
store i32 %38, i32* %11
br label %39
39: ; preds = %36
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %32
42: ; preds = %32
br label %43
43: ; preds = %42, %30
%44 = load i32, i32* %11
%45 = mul nsw i32 4, %44
%46 = add nsw i32 54, %45
%47 = sext i32 %46 to i64
store i64 %47, i64* %12
%48 = load i32*, i32** %6
%49 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %48)
%50 = load i64, i64* %12
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = mul i64 %52, %54
%56 = add i64 %50, %55
%57 = trunc i64 %56 to i32
%58 = load i32*, i32** %6
%59 = call i32 @fputc4LowHigh(i32 %57, i32* %58)
%60 = load i32*, i32** %6
%61 = call i32 @fputc2LowHigh(i32 0, i32* %60)
%62 = load i32*, i32** %6
%63 = call i32 @fputc2LowHigh(i32 0, i32* %62)
%64 = load i64, i64* %12
%65 = trunc i64 %64 to i32
%66 = load i32*, i32** %6
%67 = call i32 @fputc4LowHigh(i32 %65, i32* %66)
%68 = load i32*, i32** %6
%69 = call i32 @fputc4LowHigh(i32 40, i32* %68)
%70 = load i32, i32* %7
%71 = load i32*, i32** %6
%72 = call i32 @fputc4LowHigh(i32 %70, i32* %71)
%73 = load i32, i32* %8
%74 = load i32*, i32** %6
%75 = call i32 @fputc4LowHigh(i32 %73, i32* %74)
%76 = load i32*, i32** %6
%77 = call i32 @fputc2LowHigh(i32 1, i32* %76)
%78 = load i32, i32* %9
%79 = load i32*, i32** %6
%80 = call i32 @fputc2LowHigh(i32 %78, i32* %79)
%81 = load i32*, i32** %6
%82 = call i32 @fputc4LowHigh(i32 0, i32* %81)
%83 = load i32*, i32** %6
%84 = call i32 @fputc4LowHigh(i32 0, i32* %83)
%85 = load i32*, i32** %6
%86 = call i32 @fputc4LowHigh(i32 0, i32* %85)
%87 = load i32*, i32** %6
%88 = call i32 @fputc4LowHigh(i32 0, i32* %87)
%89 = load i32*, i32** %6
%90 = call i32 @fputc4LowHigh(i32 0, i32* %89)
%91 = load i32*, i32** %6
%92 = call i32 @fputc4LowHigh(i32 0, i32* %91)
%93 = load i32*, i32** %6
%94 = call i64 @ferror(i32* %93)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %43
store i32 0, i32* %5
br label %98
97: ; preds = %43
store i32 1, i32* %5
br label %98
98: ; preds = %97, %96, %26, %18
%99 = load i32, i32* %5
ret i32 %99
}

LLVM IR (-O2):
@.str = [3 x i8] c"BM\00"
define i32 @putBmpHeader(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp slt i32 %1, 1
%6 = icmp slt i32 %2, 1
%7 = or i1 %5, %6
%8 = icmp eq i32* %0, null
%9 = or i1 %8, %7
br i1 %9, label %68, label %10
10: ; preds = %4
%11 = tail call i64 @ferror(i32* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %68
13: ; preds = %10
%14 = icmp eq i32 %3, 24
br i1 %14, label %45, label %15
15: ; preds = %13
%16 = icmp slt i32 %3, 1
br i1 %16, label %45, label %17
17: ; preds = %15
%18 = add i32 %3, -1
%19 = and i32 %3, 7
%20 = icmp ult i32 %18, 7
br i1 %20, label %31, label %21
21: ; preds = %17
%22 = and i32 %3, -8
br label %23
23: ; preds = %23, %21
%24 = phi i32 [ 1, %21 ], [ %26, %23 ]
%25 = phi i32 [ 0, %21 ], [ %27, %23 ]
%26 = shl i32 %24, 8
%27 = add i32 %25, 8
%28 = icmp eq i32 %27, %22
br i1 %28, label %29, label %23
29: ; preds = %23
%30 = shl i32 %24, 7
br label %31
31: ; preds = %29, %17
%32 = phi i32 [ undef, %17 ], [ %30, %29 ]
%33 = phi i32 [ 1, %17 ], [ %26, %29 ]
%34 = icmp eq i32 %19, 0
br i1 %34, label %41, label %35
35: ; preds = %31, %35
%36 = phi i32 [ %38, %35 ], [ %33, %31 ]
%37 = phi i32 [ %39, %35 ], [ 0, %31 ]
%38 = shl nsw i32 %36, 1
%39 = add i32 %37, 1
%40 = icmp eq i32 %39, %19
br i1 %40, label %41, label %35
41: ; preds = %35, %31
%42 = phi i32 [ %32, %31 ], [ %36, %35 ]
%43 = shl i32 %42, 3
%44 = add i32 %43, 54
br label %45
45: ; preds = %41, %15, %13
%46 = phi i32 [ 54, %13 ], [ 58, %15 ], [ %44, %41 ]
%47 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %0)
%48 = mul i32 %2, %1
%49 = add i32 %46, %48
%50 = tail call i32 @fputc4LowHigh(i32 %49, i32* %0)
%51 = tail call i32 @fputc2LowHigh(i32 0, i32* %0)
%52 = tail call i32 @fputc2LowHigh(i32 0, i32* %0)
%53 = tail call i32 @fputc4LowHigh(i32 %46, i32* %0)
%54 = tail call i32 @fputc4LowHigh(i32 40, i32* %0)
%55 = tail call i32 @fputc4LowHigh(i32 %1, i32* %0)
%56 = tail call i32 @fputc4LowHigh(i32 %2, i32* %0)
%57 = tail call i32 @fputc2LowHigh(i32 1, i32* %0)
%58 = tail call i32 @fputc2LowHigh(i32 %3, i32* %0)
%59 = tail call i32 @fputc4LowHigh(i32 0, i32* %0)
%60 = tail call i32 @fputc4LowHigh(i32 0, i32* %0)
%61 = tail call i32 @fputc4LowHigh(i32 0, i32* %0)
%62 = tail call i32 @fputc4LowHigh(i32 0, i32* %0)
%63 = tail call i32 @fputc4LowHigh(i32 0, i32* %0)
%64 = tail call i32 @fputc4LowHigh(i32 0, i32* %0)
%65 = tail call i64 @ferror(i32* %0)
%66 = icmp eq i64 %65, 0
%67 = zext i1 %66 to i32
br label %68
68: ; preds = %45, %10, %4
%69 = phi i32 [ 0, %4 ], [ 0, %10 ], [ %67, %45 ]
ret i32 %69
}