#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 /*<<< orphan*/ printf(char *);
int check_magic(unsigned char *buf) {
  const char *magic = "ELF";
  int i;
  for (i = 0; i < 4; i++)
    if (!(buf[i] == magic[i])) {
      printf("ELF Magic number test failed.");
      return 1;
    }
  return 0;
}


x86 assembly (clang, -O0):
<check_magic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xedd(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    1183 <check_magic+0x73>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1170 <check_magic+0x60>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    118a <check_magic+0x7a>
jmp    1175 <check_magic+0x65>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <check_magic+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_magic>:
push   %rax
cmpb   $0x7f,(%rdi)
jne    112a <check_magic+0x1a>
cmpb   $0x45,0x1(%rdi)
jne    112a <check_magic+0x1a>
cmpb   $0x4c,0x2(%rdi)
jne    112a <check_magic+0x1a>
xor    %eax,%eax
cmpb   $0x46,0x3(%rdi)
je     113b <check_magic+0x2b>
lea    0xecf(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\7FELF\00"
@.str.1 = [30 x i8] c"ELF Magic number test failed.\00"
define i32 @check_magic(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
store i32 0, i32* %5
br label %6
6: ; preds = %26, %1
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 4
br i1 %8, label %9, label %29
9: ; preds = %6
%10 = load i8*, i8** %3
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %15, %21
br i1 %22, label %25, label %23
23: ; preds = %9
%24 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %30
25: ; preds = %9
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %6
29: ; preds = %6
store i32 0, i32* %2
br label %30
30: ; preds = %29, %23
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"ELF Magic number test failed.\00"
define i32 @check_magic(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 127
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 69
br i1 %7, label %8, label %16
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %0, i64 2
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 76
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %0, i64 3
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 70
br i1 %15, label %18, label %16
16: ; preds = %12, %8, %4, %1
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %12, %16
%19 = phi i32 [ 1, %16 ], [ 0, %12 ]
ret i32 %19
}