#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 */
struct magic_set {
  int dummy;
};

/* Variables and functions */
int file_buffer(struct magic_set *, int, int /*<<< orphan*/ *, void const *,
                size_t);
char const *file_getbuffer(struct magic_set *);
int file_reset(struct magic_set *);
const char *magic_buffer(struct magic_set *ms, const void *buf, size_t nb) {
  if (file_reset(ms) == -1)
    return NULL;
  if (file_buffer(ms, -1, NULL, buf, nb) == -1) {
    return NULL;
  }
  return file_getbuffer(ms);
}


x86 assembly (clang, -O0):
<magic_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <file_reset@plt>
cmp    $0xffffffff,%eax
jne    1163 <magic_buffer+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <magic_buffer+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0xffffffff,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <file_buffer@plt>
cmp    $0xffffffff,%eax
jne    1193 <magic_buffer+0x63>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <magic_buffer+0x70>
mov    -0x10(%rbp),%rdi
call   1050 <file_getbuffer@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<magic_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <file_reset@plt>
cmp    $0xffffffff,%eax
je     116f <magic_buffer+0x3f>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
xor    %edx,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <file_buffer@plt>
cmp    $0xffffffff,%eax
je     116f <magic_buffer+0x3f>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <file_getbuffer@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.magic_set = type { i32 }
define i8* @magic_buffer(%struct.magic_set* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca %struct.magic_set*
%6 = alloca i8*
%7 = alloca i64
store %struct.magic_set* %0, %struct.magic_set** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%8 = load %struct.magic_set*, %struct.magic_set** %5
%9 = call i32 @file_reset(%struct.magic_set* %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %3
store i8* null, i8** %4
br label %22
12: ; preds = %3
%13 = load %struct.magic_set*, %struct.magic_set** %5
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = call i32 @file_buffer(%struct.magic_set* %13, i32 -1, i32* null, i8* %14, i64 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %12
store i8* null, i8** %4
br label %22
19: ; preds = %12
%20 = load %struct.magic_set*, %struct.magic_set** %5
%21 = call i8* @file_getbuffer(%struct.magic_set* %20)
store i8* %21, i8** %4
br label %22
22: ; preds = %19, %18, %11
%23 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
%struct.magic_set = type { i32 }
define i8* @magic_buffer(%struct.magic_set* %0, i8* %1, i64 %2) {
%4 = tail call i32 @file_reset(%struct.magic_set* %0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i32 @file_buffer(%struct.magic_set* %0, i32 -1, i32* null, i8* %1, i64 %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i8* @file_getbuffer(%struct.magic_set* %0)
br label %11
11: ; preds = %6, %3, %9
%12 = phi i8* [ %10, %9 ], [ null, %3 ], [ null, %6 ]
ret i8* %12
}