#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int qemu_remove_mapping(unsigned int addr) {
  char buf[((4 * 1024) + 20)];
  int fd = open("/sys/qemu_trace/symbol", O_WRONLY);
  if (fd < 0)
    return fd;
  sprintf(buf, "%x\n", addr);
  write(fd, buf, strlen(buf));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<qemu_remove_mapping>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0x0,-0x1024(%rbp)
jge    1194 <qemu_remove_mapping+0x44>
mov    -0x1024(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <qemu_remove_mapping+0xa6>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe72(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x1024(%rbp),%eax
mov    %eax,-0x1034(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1034(%rbp),%edi
mov    -0x1030(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x1024(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qemu_remove_mapping>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1020,%rsp
mov    %edi,%ebp
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11a9 <qemu_remove_mapping+0x59>
lea    0xe98(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1070 <sprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x1020,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/sys/qemu_trace/symbol\00"
@O_WRONLY = global i32 0
@.str.1 = [4 x i8] c"%x\0A\00"
define i32 @qemu_remove_mapping(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4116 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %5
store i32 %11, i32* %2
br label %23
12: ; preds = %1
%13 = getelementptr inbounds [4116 x i8], [4116 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %5
%17 = getelementptr inbounds [4116 x i8], [4116 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [4116 x i8], [4116 x i8]* %4, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @write(i32 %16, i8* %17, i32 %19)
%21 = load i32, i32* %5
%22 = call i32 @close(i32 %21)
store i32 0, i32* %2
br label %23
23: ; preds = %12, %10
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [23 x i8] c"/sys/qemu_trace/symbol\00"
@O_WRONLY = global i32 0
@.str.1 = [4 x i8] c"%x\0A\00"
define i32 @qemu_remove_mapping(i32 %0) {
%2 = alloca [4116 x i8]
%3 = getelementptr inbounds [4116 x i8], [4116 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%9 = call i32 @strlen(i8* %3)
%10 = call i32 @write(i32 %5, i8* %3, i32 %9)
%11 = call i32 @close(i32 %5)
br label %12
12: ; preds = %1, %7
%13 = phi i32 [ 0, %7 ], [ %5, %1 ]
ret i32 %13
}