void gen_field(const char *prefix, const char *struct_name, const char *type,
               const char *field, int offset, int size) {
  printf("(def-syntax %s%s-%s-offset %d)\n", prefix, struct_name, field,
         offset);
  printf("(def-syntax %s%s-%s-size %d)\n", prefix, struct_name, field, size);
  printf("(def-syntax %s%s-%s-type \"%s\")\n", prefix, struct_name, field,
         type);
  if (strcmp(type, "int ") == 0 || strcmp(type, "unsigned int ") == 0) {
    printf("(def-syntax (%s%s-get-%s ?x)\n  (c-get-int ?x %d))\n", prefix,
           struct_name, field, offset);
    printf("(def-syntax (%s%s-set-%s ?x ?v)\n  (c-set-int ?x %d ?v))\n", prefix,
           struct_name, field, offset);
  } else if (strcmp(type, "short ") == 0 ||
             strcmp(type, "unsigned short ") == 0) {
    printf("(def-syntax (%s%s-get-%s ?x)\n  (c-get-short ?x %d))\n", prefix,
           struct_name, field, offset);
    printf("(def-syntax (%s%s-set-%s ?x ?v)\n  (c-set-short ?x %d ?v))\n",
           prefix, struct_name, field, offset);
  }
}


x86 assembly (clang, -O0):
<gen_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8d
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     11cc <gen_field+0xac>
mov    -0x18(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    120d <gen_field+0xed>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1280 <gen_field+0x160>
mov    -0x18(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     123f <gen_field+0x11f>
mov    -0x18(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    127b <gen_field+0x15b>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1280 <gen_field+0x160>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_field>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xebf(%rip),%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r8d,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedb(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
lea    0xf04(%rip),%rcx
mov    %rcx,(%rsp)
lea    0xec6(%rip),%r14
test   %eax,%eax
je     1204 <gen_field+0xe4>
lea    0xead(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1204 <gen_field+0xe4>
lea    0xf1d(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
lea    0xf4a(%rip),%rcx
mov    %rcx,(%rsp)
lea    0xf0a(%rip),%r14
test   %eax,%eax
je     1204 <gen_field+0xe4>
lea    0xeef(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1204 <gen_field+0xe4>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %ebp,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %ebp,%r8d
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"(def-syntax %s%s-%s-offset %d)\0A\00"
@.str.1 = [30 x i8] c"(def-syntax %s%s-%s-size %d)\0A\00"
@.str.2 = [32 x i8] c"(def-syntax %s%s-%s-type \22%s\22)\0A\00"
@.str.3 = [5 x i8] c"int \00"
@.str.4 = [14 x i8] c"unsigned int \00"
@.str.5 = [51 x i8] c"(def-syntax (%s%s-get-%s ?x)\0A (c-get-int ?x %d))\0A\00"
@.str.6 = [57 x i8] c"(def-syntax (%s%s-set-%s ?x ?v)\0A (c-set-int ?x %d ?v))\0A\00"
@.str.7 = [7 x i8] c"short \00"
@.str.8 = [16 x i8] c"unsigned short \00"
@.str.9 = [53 x i8] c"(def-syntax (%s%s-get-%s ?x)\0A (c-get-short ?x %d))\0A\00"
@.str.10 = [59 x i8] c"(def-syntax (%s%s-set-%s ?x ?v)\0A (c-set-short ?x %d ?v))\0A\00"
define void @gen_field(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%13 = load i8*, i8** %7
%14 = load i8*, i8** %8
%15 = load i8*, i8** %10
%16 = load i32, i32* %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14, i8* %15, i32 %16)
%18 = load i8*, i8** %7
%19 = load i8*, i8** %8
%20 = load i8*, i8** %10
%21 = load i32, i32* %12
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %7
%24 = load i8*, i8** %8
%25 = load i8*, i8** %10
%26 = load i8*, i8** %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %24, i8* %25, i8* %26)
%28 = load i8*, i8** %9
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %6
%32 = load i8*, i8** %9
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %31, %6
%36 = load i8*, i8** %7
%37 = load i8*, i8** %8
%38 = load i8*, i8** %10
%39 = load i32, i32* %11
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i8* %36, i8* %37, i8* %38, i32 %39)
%41 = load i8*, i8** %7
%42 = load i8*, i8** %8
%43 = load i8*, i8** %10
%44 = load i32, i32* %11
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.6, i64 0, i64 0), i8* %41, i8* %42, i8* %43, i32 %44)
br label %66
46: ; preds = %31
%47 = load i8*, i8** %9
%48 = call i32 @strcmp(i8* %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%49 = icmp eq i32 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %46
%51 = load i8*, i8** %9
%52 = call i32 @strcmp(i8* %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %65
54: ; preds = %50, %46
%55 = load i8*, i8** %7
%56 = load i8*, i8** %8
%57 = load i8*, i8** %10
%58 = load i32, i32* %11
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0), i8* %55, i8* %56, i8* %57, i32 %58)
%60 = load i8*, i8** %7
%61 = load i8*, i8** %8
%62 = load i8*, i8** %10
%63 = load i32, i32* %11
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.10, i64 0, i64 0), i8* %60, i8* %61, i8* %62, i32 %63)
br label %65
65: ; preds = %54, %50
br label %66
66: ; preds = %65, %35
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"(def-syntax %s%s-%s-offset %d)\0A\00"
@.str.1 = [30 x i8] c"(def-syntax %s%s-%s-size %d)\0A\00"
@.str.2 = [32 x i8] c"(def-syntax %s%s-%s-type \22%s\22)\0A\00"
@.str.3 = [5 x i8] c"int \00"
@.str.4 = [14 x i8] c"unsigned int \00"
@.str.5 = [51 x i8] c"(def-syntax (%s%s-get-%s ?x)\0A (c-get-int ?x %d))\0A\00"
@.str.6 = [57 x i8] c"(def-syntax (%s%s-set-%s ?x ?v)\0A (c-set-int ?x %d ?v))\0A\00"
@.str.7 = [7 x i8] c"short \00"
@.str.8 = [16 x i8] c"unsigned short \00"
@.str.9 = [53 x i8] c"(def-syntax (%s%s-get-%s ?x)\0A (c-get-short ?x %d))\0A\00"
@.str.10 = [59 x i8] c"(def-syntax (%s%s-set-%s ?x ?v)\0A (c-set-short ?x %d ?v))\0A\00"
define void @gen_field(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %3, i32 %4)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %3, i32 %5)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1, i8* %3, i8* %2)
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %6
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %15, %18, %6, %12
%22 = phi i8* [ getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), %12 ], [ getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), %6 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0), %18 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0), %15 ]
%23 = phi i8* [ getelementptr inbounds ([57 x i8], [57 x i8]* @.str.6, i64 0, i64 0), %12 ], [ getelementptr inbounds ([57 x i8], [57 x i8]* @.str.6, i64 0, i64 0), %6 ], [ getelementptr inbounds ([59 x i8], [59 x i8]* @.str.10, i64 0, i64 0), %18 ], [ getelementptr inbounds ([59 x i8], [59 x i8]* @.str.10, i64 0, i64 0), %15 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %22, i8* %0, i8* %1, i8* %3, i32 %4)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %23, i8* %0, i8* %1, i8* %3, i32 %4)
br label %26
26: ; preds = %21, %18
ret void
}