#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 */
char *convertByteToBin(unsigned char);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *initiateTarga(char *, int, int);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, char *, char *);
void createTarga(char *filename) {
  FILE *file = NULL;
  int cpt = 0, width = 1000, height = 1000;
  unsigned char p, ps;
  file = initiateTarga(filename, width, height);
  while (cpt < width * height) {
    p = cpt % 256;
    ps = p ^ 0x01;
    printf("%d 0x%02x 0b%s 0b%s\n", p, p, convertByteToBin(p),
           convertByteToBin(ps));
    fwrite(&p, sizeof(unsigned char), 1, file);
    cpt++;
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<createTarga>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x3e8,-0x18(%rbp)
movl   $0x3e8,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <initiateTarga@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jge    121b <createTarga+0xcb>
mov    -0x14(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x1d(%rbp)
movzbl -0x1d(%rbp),%eax
xor    $0x1,%eax
mov    %al,-0x1e(%rbp)
mov    -0x1d(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x1d(%rbp),%al
mov    %al,-0x1f(%rbp)
movzbl -0x1d(%rbp),%edi
call   1060 <convertByteToBin@plt>
mov    %rax,-0x28(%rbp)
movzbl -0x1e(%rbp),%edi
call   1060 <convertByteToBin@plt>
mov    -0x29(%rbp),%dl
mov    -0x28(%rbp),%rcx
mov    %rax,%r8
mov    -0x1f(%rbp),%al
lea    0xe12(%rip),%rdi
movzbl %dl,%esi
movzbl %al,%edx
call   1040 <printf@plt>
mov    -0x10(%rbp),%rcx
lea    -0x1d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118c <createTarga+0x3c>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createTarga>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x3e8,%esi
mov    $0x3e8,%edx
call   1060 <initiateTarga@plt>
mov    %rax,%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl %bpl,%r13d
mov    %ebp,%r14d
xor    $0x1,%r14b
mov    %r13d,%edi
call   1070 <convertByteToBin@plt>
mov    %rax,%r12
movzbl %r14b,%edi
call   1070 <convertByteToBin@plt>
lea    0xe5a(%rip),%rdi
mov    %r13d,%esi
mov    %r13d,%edx
mov    %r12,%rcx
mov    %rax,%r8
call   1040 <printf@plt>
mov    %ebx,%edi
sar    $0x18,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
add    $0x1,%ebp
add    $0x1000000,%ebx
cmp    $0xf4240,%ebp
jne    1180 <createTarga+0x30>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"%d 0x%02x 0b%s 0b%s\0A\00"
define void @createTarga(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
store i8* %0, i8** %2
store i32* null, i32** %3
store i32 0, i32* %4
store i32 1000, i32* %5
store i32 1000, i32* %6
%9 = load i8*, i8** %2
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32* @initiateTarga(i8* %9, i32 %10, i32 %11)
store i32* %12, i32** %3
br label %13
13: ; preds = %19, %1
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = mul nsw i32 %15, %16
%18 = icmp slt i32 %14, %17
br i1 %18, label %19, label %38
19: ; preds = %13
%20 = load i32, i32* %4
%21 = srem i32 %20, 256
%22 = trunc i32 %21 to i8
store i8 %22, i8* %7
%23 = load i8, i8* %7
%24 = zext i8 %23 to i32
%25 = xor i32 %24, 1
%26 = trunc i32 %25 to i8
store i8 %26, i8* %8
%27 = load i8, i8* %7
%28 = load i8, i8* %7
%29 = load i8, i8* %7
%30 = call i8* @convertByteToBin(i8 zeroext %29)
%31 = load i8, i8* %8
%32 = call i8* @convertByteToBin(i8 zeroext %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8 zeroext %27, i8 zeroext %28, i8* %30, i8* %32)
%34 = load i32*, i32** %3
%35 = call i32 @fwrite(i8* %7, i32 1, i32 1, i32* %34)
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %13
38: ; preds = %13
%39 = load i32*, i32** %3
%40 = call i32 @fclose(i32* %39)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"%d 0x%02x 0b%s 0b%s\0A\00"
define void @createTarga(i8* %0) {
%2 = tail call i32* @initiateTarga(i8* %0, i32 1000, i32 1000)
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 0, %1 ], [ %13, %3 ]
%5 = trunc i32 %4 to i8
%6 = xor i8 %5, 1
%7 = tail call i8* @convertByteToBin(i8 zeroext %5)
%8 = tail call i8* @convertByteToBin(i8 zeroext %6)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8 zeroext %5, i8 zeroext %5, i8* %7, i8* %8)
%10 = shl i32 %4, 24
%11 = ashr exact i32 %10, 24
%12 = tail call i32 @fputc(i32 %11, i32* %2)
%13 = add nuw nsw i32 %4, 1
%14 = icmp eq i32 %13, 1000000
br i1 %14, label %15, label %3
15: ; preds = %3
%16 = tail call i32 @fclose(i32* %2)
ret void
}