#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 *, char const *, char const *, unsigned long,
                          unsigned int, unsigned int);
void set_reg(const char *name, const char *type, unsigned long address,
             unsigned int value,
             unsigned int (*get)(unsigned long, const char *),
             void (*set)(unsigned long, const char *, unsigned int)) {
  unsigned int readback;
  readback = get(address, name);
  printf("OLD: %s (%s%04lx)\t0x%08x (%d)\n", name, type, address, readback,
         readback);
  set(address, name, value);
  readback = get(address, name);
  printf("NEW: %s (%s%04lx)\t0x%08x (%d)\n", name, type, address, readback,
         readback);
}


x86 assembly (clang, -O0):
<set_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   *%rax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x34(%rbp),%r8d
mov    -0x34(%rbp),%r9d
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   *%rax
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   *%rax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x34(%rbp),%r8d
mov    -0x34(%rbp),%r9d
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_reg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r12
mov    %r8,%r13
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,%rdi
mov    %rbx,%rsi
call   *%r8
lea    0xec4(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %eax,%r8d
mov    %eax,%r9d
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   *%r12
mov    %r15,%rdi
mov    %rbx,%rsi
call   *%r13
lea    0xeb4(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %eax,%r8d
mov    %eax,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"OLD: %s (%s%04lx)\090x%08x (%d)\0A\00"
@.str.1 = [31 x i8] c"NEW: %s (%s%04lx)\090x%08x (%d)\0A\00"
define void @set_reg(i8* %0, i8* %1, i64 %2, i32 %3, i32 (i64, i8*)* %4, void (i64, i8*, i32)* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32 (i64, i8*)*
%12 = alloca void (i64, i8*, i32)*
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 (i64, i8*)* %4, i32 (i64, i8*)** %11
store void (i64, i8*, i32)* %5, void (i64, i8*, i32)** %12
%14 = load i32 (i64, i8*)*, i32 (i64, i8*)** %11
%15 = load i64, i64* %9
%16 = load i8*, i8** %7
%17 = call i32 %14(i64 %15, i8* %16)
store i32 %17, i32* %13
%18 = load i8*, i8** %7
%19 = load i8*, i8** %8
%20 = load i64, i64* %9
%21 = load i32, i32* %13
%22 = load i32, i32* %13
%23 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19, i64 %20, i32 %21, i32 %22)
%24 = load void (i64, i8*, i32)*, void (i64, i8*, i32)** %12
%25 = load i64, i64* %9
%26 = load i8*, i8** %7
%27 = load i32, i32* %10
%28 = load i32 (i64, i8*)*, i32 (i64, i8*)** %11
%29 = load i64, i64* %9
%30 = load i8*, i8** %7
%31 = call i32 %28(i64 %29, i8* %30)
store i32 %31, i32* %13
%32 = load i8*, i8** %7
%33 = load i8*, i8** %8
%34 = load i64, i64* %9
%35 = load i32, i32* %13
%36 = load i32, i32* %13
%37 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %33, i64 %34, i32 %35, i32 %36)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"OLD: %s (%s%04lx)\090x%08x (%d)\0A\00"
@.str.1 = [31 x i8] c"NEW: %s (%s%04lx)\090x%08x (%d)\0A\00"
define void @set_reg(i8* %0, i8* %1, i64 %2, i32 %3, i32 (i64, i8*)* nocapture %4, void (i64, i8*, i32)* nocapture %5) {
%7 = tail call i32 %4(i64 %2, i8* %0)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i64 %2, i32 %7, i32 %7)
tail call void %5(i64 %2, i8* %0, i32 %3)
%9 = tail call i32 %4(i64 %2, i8* %0)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i64 %2, i32 %9, i32 %9)
ret void
}