#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 macro_arg {
  int dummy;
};
struct hash_entry {
  int dummy;
};
struct compile_state {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ do_define_macro(struct compile_state *, struct hash_entry *,
                                   char *, int, struct macro_arg *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *xmalloc(int, char *);
void define_macro(struct compile_state *state, struct hash_entry *ident,
                  const char *body, int body_len, int argc,
                  struct macro_arg *args) {
  char *buf;
  buf = xmalloc(body_len + 1, "macro buf");
  memcpy(buf, body, body_len);
  buf[body_len] = '\0';
  do_define_macro(state, ident, buf, argc, args);
}


x86 assembly (clang, -O0):
<define_macro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
lea    0xea4(%rip),%rsi
call   1040 <xmalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8
call   1030 <do_define_macro@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<define_macro>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r13
lea    0x1(%rbx),%edi
lea    0xea9(%rip),%rsi
call   1040 <xmalloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    (%rsp),%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <do_define_macro@plt>

LLVM IR (-O0):
%struct.compile_state = type { i32 }
%struct.hash_entry = type { i32 }
%struct.macro_arg = type { i32 }
@.str = [10 x i8] c"macro buf\00"
define void @define_macro(%struct.compile_state* %0, %struct.hash_entry* %1, i8* %2, i32 %3, i32 %4, %struct.macro_arg* %5) {
%7 = alloca %struct.compile_state*
%8 = alloca %struct.hash_entry*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.macro_arg*
%13 = alloca i8*
store %struct.compile_state* %0, %struct.compile_state** %7
store %struct.hash_entry* %1, %struct.hash_entry** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store %struct.macro_arg* %5, %struct.macro_arg** %12
%14 = load i32, i32* %10
%15 = add nsw i32 %14, 1
%16 = call i8* @xmalloc(i32 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %13
%17 = load i8*, i8** %13
%18 = load i8*, i8** %9
%19 = load i32, i32* %10
%20 = call i32 @memcpy(i8* %17, i8* %18, i32 %19)
%21 = load i8*, i8** %13
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
%25 = load %struct.compile_state*, %struct.compile_state** %7
%26 = load %struct.hash_entry*, %struct.hash_entry** %8
%27 = load i8*, i8** %13
%28 = load i32, i32* %11
%29 = load %struct.macro_arg*, %struct.macro_arg** %12
%30 = call i32 @do_define_macro(%struct.compile_state* %25, %struct.hash_entry* %26, i8* %27, i32 %28, %struct.macro_arg* %29)
ret void
}

LLVM IR (-O2):
%struct.compile_state = type { i32 }
%struct.hash_entry = type { i32 }
%struct.macro_arg = type { i32 }
@.str = [10 x i8] c"macro buf\00"
define void @define_macro(%struct.compile_state* %0, %struct.hash_entry* %1, i8* %2, i32 %3, i32 %4, %struct.macro_arg* %5) {
%7 = add nsw i32 %3, 1
%8 = tail call i8* @xmalloc(i32 %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @memcpy(i8* %8, i8* %2, i32 %3)
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
store i8 0, i8* %11
%12 = tail call i32 @do_define_macro(%struct.compile_state* %0, %struct.hash_entry* %1, i8* %8, i32 %4, %struct.macro_arg* %5)
ret void
}