#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*/ exit(int);
int fprintf(int /*<<< orphan*/ *, char *, unsigned char);
int /*<<< orphan*/ printf(char *);
void add_magic_num(FILE *file) {
  unsigned char magic_num[4] = {0x4C, 0x70, 0xF0, 0x7C};
  int i = 0, ret = 0;
  for (i = 0; i < 4; i++) {
    if ((ret = fprintf(file, "%c", magic_num[i])) != 1) {
      printf("Failure to add magic number to output file.\n");
      exit(1);
    }
  }
  return;
}


x86 assembly (clang, -O0):
<add_magic_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xebe(%rip),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    11b2 <add_magic_num+0x82>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
lea    0xe91(%rip),%rsi
movzbl -0xc(%rbp,%rax,1),%edx
call   1040 <fprintf@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x1,%eax
je     119f <add_magic_num+0x6f>
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11a4 <add_magic_num+0x74>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115a <add_magic_num+0x2a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_magic_num>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rsi
mov    $0x4c,%edx
call   1040 <fprintf@plt>
cmp    $0x1,%eax
jne    1197 <add_magic_num+0x67>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x70,%edx
call   1040 <fprintf@plt>
cmp    $0x1,%eax
jne    1197 <add_magic_num+0x67>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
mov    $0xf0,%edx
call   1040 <fprintf@plt>
cmp    $0x1,%eax
jne    1197 <add_magic_num+0x67>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7c,%edx
call   1040 <fprintf@plt>
cmp    $0x1,%eax
jne    1197 <add_magic_num+0x67>
pop    %rbx
ret
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@__const.add_magic_num.magic_num = [4 x i8] c"Lp\F0|"
@.str = [3 x i8] c"%c\00"
@.str.1 = [45 x i8] c"Failure to add magic number to output file.\0A\00"
define void @add_magic_num(i32* %0) {
%2 = alloca i32*
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = bitcast [4 x i8]* %3 to i8*
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %4
br label %7
7: ; preds = %22, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %15)
store i32 %16, i32* %5
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %10
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %7
25: ; preds = %7
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@str = [44 x i8] c"Failure to add magic number to output file.\00"
define void @add_magic_num(i32* nocapture %0) {
%2 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext 76)
%3 = icmp eq i32 %2, 1
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext 112)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext -16)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext 124)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %10
ret void
14: ; preds = %10, %7, %4, %1
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
}