LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/screen.c
// Function: switch_vdesk
void switch_vdesk(ScreenInfo *s, unsigned int v) {
	struct list *iter;
#ifdef DEBUG
	int hidden = 0, raised = 0;
#endif

	if (v == s->vdesk)
		return;
	LOG_ENTER("switch_vdesk(screen=%d, from=%d, to=%d)", s->screen, s->vdesk, v);
	if (current && !is_fixed(current)) {
		select_client(NULL);
	}
	for (iter = clients_tab_order; iter; iter = iter->next) {
		Client *c = iter->data;
		if (c->screen != s)
			continue;
		if (c->vdesk == s->vdesk) {
			client_hide(c);
#ifdef DEBUG
			hidden++;
#endif
		} else if (c->vdesk == v) {
			if (!c->is_dock || s->docks_visible)
				client_show(c);
#ifdef DEBUG
			raised++;
#endif
		}
	}
	/* cache the value of the current vdesk, so that user may toggle back to it */
	s->old_vdesk = s->vdesk;
	s->vdesk = v;
	ewmh_set_net_current_desktop(s);
	LOG_DEBUG("%d hidden, %d raised\n", hidden, raised);
	LOG_LEAVE();
}

// Assembly:
cmpl %esi, 0x40(%rdi)
jne 0x7f32
retq
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x486e(%rip), %rax      # 0xc7b0
movq (%rax), %rax
testq %rax, %rax
je 0x7f57
cmpl $-0x1, 0x74(%rax)
je 0x7f57
xorl %edi, %edi
callq 0x3cc8
leaq 0x483a(%rip), %rax      # 0xc798
movq (%rax), %r14
testq %r14, %r14
je 0x7f99
movq 0x8(%r14), %rdi
cmpq %rbx, 0x10(%rdi)
jne 0x7f94
movl 0x74(%rdi), %eax
cmpl 0x40(%rbx), %eax
jne 0x7f7f
callq 0x39e0
jmp 0x7f94
cmpl %ebp, %eax
jne 0x7f94
cmpl $0x0, 0x78(%rdi)
je 0x7f8f
cmpl $0x0, 0x68(%rbx)
je 0x7f94
callq 0x3a87
movq (%r14), %r14
jmp 0x7f61
movl 0x40(%rbx), %eax
movl %eax, 0x58(%rbx)
movl %ebp, 0x40(%rbx)
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x58f5
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/screen.c
// Function: set_docks_visible
void set_docks_visible(ScreenInfo *s, int is_visible) {
	struct list *iter;

	LOG_ENTER("set_docks_visible(screen=%d, is_visible=%d)", s->screen, is_visible);
	s->docks_visible = is_visible;
	for (iter = clients_tab_order; iter; iter = iter->next) {
		Client *c = iter->data;
		if (c->screen != s)
			continue;
		if (c->is_dock) {
			if (is_visible) {
#ifdef VWM
				if (is_fixed(c) || (c->vdesk == s->vdesk)) {
#endif
					client_show(c);
					client_raise(c);
#ifdef VWM
				}
#endif
			} else {
				client_hide(c);
			}
		}
	}
	LOG_LEAVE();
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %esi, 0x68(%rdi)
leaq 0x47d8(%rip), %rax      # 0xc798
movq (%rax), %r12
testq %r12, %r12
je 0x8019
movl %esi, %ebx
movq %rdi, %r14
movq 0x8(%r12), %r15
cmpq %r14, 0x10(%r15)
je 0x7fe3
movq (%r12), %r12
testq %r12, %r12
jne 0x7fcd
jmp 0x8019
cmpl $0x0, 0x78(%r15)
je 0x7fd8
testl %ebx, %ebx
je 0x800f
movl 0x74(%r15), %eax
cmpl $-0x1, %eax
je 0x7ffd
cmpl 0x40(%r14), %eax
jne 0x7fd8
movq %r15, %rdi
callq 0x3a87
movq %r15, %rdi
callq 0x3ae2
jmp 0x7fd8
movq %r15, %rdi
callq 0x39e0
jmp 0x7fd8
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/screen.c
// Function: find_screen
ScreenInfo *find_screen(Window root) {
	int i;
	for (i = 0; i < num_screens; i++) {
		if (screens[i].root == root)
			return &screens[i];
	}
	return NULL;
}

// Assembly:
leaq 0x47c4(%rip), %rax      # 0xc7f0
movslq (%rax), %rcx
testq %rcx, %rcx
jle 0x804d
leaq 0x47bd(%rip), %rax      # 0xc7f8
movq (%rax), %rax
cmpq %rdi, 0x8(%rax)
je 0x804f
addq $0x70, %rax
decq %rcx
jne 0x803e
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/screen.c
// Function: find_current_screen
ScreenInfo *find_current_screen(void) {
	Window cur_root, dw;
	int di;
	unsigned int dui;

	/* XQueryPointer is useful for getting the current pointer root */
	XQueryPointer(dpy, screens[0].root, &cur_root, &dw, &di, &di, &di, &di, &dui);
	return find_screen(cur_root);
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
leaq 0x4784(%rip), %rax      # 0xc7e0
movq (%rax), %rdi
leaq 0x4792(%rip), %rbx      # 0xc7f8
movq (%rbx), %rax
movq 0x8(%rax), %rsi
subq $0x8, %rsp
leaq 0x18(%rsp), %rax
leaq 0x1c(%rsp), %r8
leaq 0x10(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %r8, %r9
pushq %rax
pushq %r8
pushq %r8
callq 0x3390
addq $0x20, %rsp
leaq 0x4753(%rip), %rax      # 0xc7f0
movslq (%rax), %rcx
testq %rcx, %rcx
jle 0x80bc
movq 0x8(%rsp), %rdx
movq (%rbx), %rax
cmpq %rdx, 0x8(%rax)
je 0x80be
addq $0x70, %rax
decq %rcx
jne 0x80ad
xorl %eax, %eax
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/screen.c
// Function: grab_keys_for_screen
void grab_keys_for_screen(ScreenInfo *s) {
	int i;
	/* Release any previous grabs */
	XUngrabKey(dpy, AnyKey, AnyModifier, s->root);
	/* Grab key combinations we're interested in */
	for (i = 0; i < NUM_GRABS; i++) {
		grab_keysym(s->root, grabmask1, keys_to_grab[i]);
	}
	for (i = 0; i < NUM_ALT_GRABS; i++) {
		grab_keysym(s->root, grabmask1 | altmask, alt_keys_to_grab[i]);
	}
	grab_keysym(s->root, grabmask2, KEY_NEXT);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
leaq 0x4709(%rip), %rax      # 0xc7e0
movq (%rax), %rdi
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
xorl %esi, %esi
movl $0x8000, %edx           # imm = 0x8000
callq 0x3600
leaq 0x42dc(%rip), %r14      # 0xc3d0
leaq 0x16f5(%rip), %r12      # 0x97f0
movq 0x8(%rbx), %rdi
movl (%r14), %esi
movq (%r15,%r12), %rdx
callq 0x8164
addq $0x8, %r15
cmpq $0xe0, %r15
jne 0x80fb
xorl %r15d, %r15d
leaq 0x42b6(%rip), %r12      # 0xc3d8
leaq 0x17a7(%rip), %r13      # 0x98d0
movq 0x8(%rbx), %rdi
movl (%r12), %esi
orl (%r14), %esi
movq (%r15,%r13), %rdx
callq 0x8164
addq $0x8, %r15
cmpq $0x28, %r15
jne 0x8129
movq 0x8(%rbx), %rdi
leaq 0x4282(%rip), %rax      # 0xc3d4
movl (%rax), %esi
movl $0xff09, %edx           # imm = 0xFF09
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x8164
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/screen.c
// Function: grab_keysym
static void grab_keysym(Window w, unsigned int mask, KeySym keysym) {
	KeyCode keycode = XKeysymToKeycode(dpy, keysym);
	XGrabKey(dpy, keycode, mask, w, True,
			GrabModeAsync, GrabModeAsync);
	XGrabKey(dpy, keycode, mask|LockMask, w, True,
			GrabModeAsync, GrabModeAsync);
	if (numlockmask) {
		XGrabKey(dpy, keycode, mask|numlockmask, w, True,
				GrabModeAsync, GrabModeAsync);
		XGrabKey(dpy, keycode, mask|numlockmask|LockMask, w, True,
				GrabModeAsync, GrabModeAsync);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x4665(%rip), %r15      # 0xc7e0
movq (%r15), %rdi
movq %rdx, %rsi
callq 0x33a0
movq (%r15), %rdi
movzbl %al, %r14d
movl $0x1, %r12d
movl %r12d, (%rsp)
movl %r14d, %esi
movl %ebp, %edx
movq %rbx, %rcx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x33d0
movq (%r15), %rdi
movl %ebp, %edx
orl $0x2, %edx
movl %r12d, (%rsp)
movl %r14d, %esi
movq %rbx, %rcx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x33d0
leaq 0x45a6(%rip), %r13      # 0xc780
movl (%r13), %edx
testl %edx, %edx
je 0x8229
movq (%r15), %rdi
orl %ebp, %edx
movl %r12d, (%rsp)
movl %r14d, %esi
movq %rbx, %rcx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x33d0
movq (%r15), %rdi
orl (%r13), %ebp
orl $0x2, %ebp
movl %r12d, (%rsp)
movl %r14d, %esi
movl %ebp, %edx
movq %rbx, %rcx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x33d0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/xconfig.c
// Function: xconfig_parse_file
enum xconfig_result xconfig_parse_file(struct xconfig_option *options,
		const char *filename) {
	struct xconfig_option *option;
	char buf[256];
	char *line, *opt, *arg;
	FILE *cfg;
	cfg = fopen(filename, "r");
	if (cfg == NULL) return XCONFIG_FILE_ERROR;
	while ((line = fgets(buf, sizeof(buf), cfg))) {
		while (isspace((int)*line))
			line++;
		if (*line == 0 || *line == '#')
			continue;
		opt = strtok(line, "\t\n\v\f\r =");
		if (opt == NULL) continue;
		option = find_option(options, opt);
		if (option == NULL) {
			fclose(cfg);
			return XCONFIG_BAD_OPTION;
		}
		if (option->type == XCONFIG_STR_LIST) {
			/* special case: spaces here mean something */
			arg = strtok(NULL, "\n\v\f\r");
			while (isspace(*arg) || *arg == '=') {
				arg++;
			}
		} else {
			arg = strtok(NULL, "\t\n\v\f\r =");
		}
		set_option(option, arg);
	}
	fclose(cfg);
	return XCONFIG_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rax
movq %rdi, %r14
leaq 0x16c6(%rip), %rsi      # 0x991c
movq %rax, %rdi
callq 0x35c0
testq %rax, %rax
je 0x8352
movq %rax, %rbx
movq %rsp, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rax, %rdx
callq 0x32d0
testq %rax, %rax
je 0x8346
movq %rax, %rbp
callq 0x3740
movq %rax, %r15
movq %rsp, %r12
leaq 0x1686(%rip), %r13      # 0x991e
movq (%r15), %rax
decq %rbp
movsbq 0x1(%rbp), %rcx
incq %rbp
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x829e
movzbl %cl, %eax
cmpl $0x23, %eax
je 0x832a
testl %eax, %eax
je 0x832a
movq %rbp, %rdi
movq %r13, %rsi
callq 0x35d0
testq %rax, %rax
je 0x832a
movq %r14, %rdi
movq %rax, %rsi
callq 0x8372
testq %rax, %rax
je 0x836b
movq %rax, %rbp
cmpl $0x3, (%rax)
jne 0x8315
xorl %edi, %edi
leaq 0x1638(%rip), %rsi      # 0x9926
callq 0x35d0
movq (%r15), %rcx
decq %rax
movsbq 0x1(%rax), %rdx
incq %rax
cmpq $0x3d, %rdx
je 0x82f9
movzwl (%rcx,%rdx,2), %edx
andl $0x2000, %edx           # imm = 0x2000
jne 0x82f9
jmp 0x831f
xorl %edi, %edi
movq %r13, %rsi
callq 0x35d0
movq %rbp, %rdi
movq %rax, %rsi
callq 0x83a8
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x32d0
movq %rax, %rbp
testq %rax, %rax
jne 0x8298
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x31a0
jmp 0x8357
movl $0x3, %ebp
movl %ebp, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %ebp
jmp 0x8348
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/xconfig.c
// Function: find_option
static struct xconfig_option *find_option(struct xconfig_option *options,
		const char *opt) {
	int i;
	for (i = 0; options[i].type != XCONFIG_END; i++) {
		if (0 == strcmp(options[i].name, opt)) {
			return &options[i];
		}
	}
	return NULL;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
cmpl $0x6, (%rdi)
je 0x839b
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x3310
testl %eax, %eax
je 0x839d
cmpl $0x6, 0x18(%rbx)
leaq 0x18(%rbx), %rbx
jne 0x8381
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/xconfig.c
// Function: set_option
static void set_option(struct xconfig_option *option, const char *arg) {
	switch (option->type) {
		case XCONFIG_BOOL:
			*(int *)option->dest = 1;
			break;
		case XCONFIG_INT:
			*(int *)option->dest = strtol(arg, NULL, 0);
			break;
		case XCONFIG_STRING:
			*(char **)option->dest = strdup(arg);
			break;
		case XCONFIG_STR_LIST:
			*(char ***)option->dest = split_string(arg);
			break;
		case XCONFIG_CALL_0:
			((void (*)(void))option->dest)();
			break;
		case XCONFIG_CALL_1:
			((void (*)(const char *))option->dest)(arg);
			break;
		default:
			break;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl (%rdi), %eax
cmpq $0x5, %rax
ja 0x85a8
movq %rsi, %rbx
movq %rdi, (%rsp)
leaq 0x1534(%rip), %rcx      # 0x9904
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
movq 0x10(%rax), %rax
movl $0x1, (%rax)
jmp 0x85a8
movq (%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *0x10(%rax)
movq %rbx, %rdi
callq 0x36c0
movq (%rsp), %rcx
movq 0x10(%rcx), %rcx
movq %rax, (%rcx)
jmp 0x85a8
movq %rbx, %rdi
callq 0x31e0
leaq 0x1(%rax), %rdi
callq 0x3430
testq %rax, %rax
je 0x859b
xorl %r14d, %r14d
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq %rax, 0x20(%rsp)
movq %rax, %r13
movzbl (%rbx), %r12d
cmpl $0x5c, %r12d
je 0x8460
testl %r12d, %r12d
jne 0x8471
jmp 0x8498
movb 0x1(%rbx), %cl
movl $0x2, %eax
testb %cl, %cl
jne 0x848c
testb %r12b, %r12b
je 0x8498
movsbq %r12b, %rbp
callq 0x3740
movq (%rax), %rcx
movl $0x1, %eax
testb $0x20, 0x1(%rcx,%rbp,2)
movl %r12d, %ecx
jne 0x8498
addq %rax, %rbx
movb %cl, (%r13)
incq %r13
jmp 0x844f
movb $0x0, (%r13)
movq 0x10(%rsp), %rax
cmpb $0x0, (%rax)
je 0x84b7
leal 0x1(%r15), %ebp
cmpl %r14d, %ebp
jge 0x84bc
movq 0x8(%rsp), %rax
jmp 0x8512
movl %r15d, %ebp
jmp 0x8526
movl %r14d, 0x1c(%rsp)
movslq %r14d, %rax
leaq 0x20(,%rax,8), %rsi
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x3510
movq %rax, %r12
testq %rax, %rax
jne 0x84fb
testq %r14, %r14
je 0x84ee
movq %r14, %rdi
callq 0x3090
movq 0x20(%rsp), %rdi
callq 0x3090
movq %r14, %rax
testq %r12, %r12
je 0x859b
movl 0x1c(%rsp), %r14d
addl $0x4, %r14d
movq %rax, 0x8(%rsp)
movslq %r15d, %rcx
movq 0x10(%rsp), %rdx
movq %rdx, (%rax,%rcx,8)
incq %r13
movq %r13, 0x10(%rsp)
callq 0x3740
movq (%rax), %rax
decq %rbx
movsbq 0x1(%rbx), %rcx
incq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x8531
movl %ebp, %r15d
testb %cl, %cl
jne 0x844f
testl %ebp, %ebp
je 0x8591
movslq %ebp, %rax
movq 0x8(%rsp), %rcx
movq $0x0, (%rcx,%rax,8)
jmp 0x859d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3360
movq (%rsp), %rcx
movq 0x10(%rcx), %rcx
movl %eax, (%rcx)
jmp 0x85a8
movq %rbx, %rdi
movq (%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *0x10(%rax)
movq 0x20(%rsp), %rdi
callq 0x3090
xorl %ecx, %ecx
movq (%rsp), %rax
movq 0x10(%rax), %rax
movq %rcx, (%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/kek[P]evilwm/xconfig.c
// Function: xconfig_parse_cli
enum xconfig_result xconfig_parse_cli(struct xconfig_option *options,
		int argc, char **argv, int *argn) {
	struct xconfig_option *option;
	int _argn;
	char *optstr;
	_argn = argn ? *argn : 1;

	while (_argn < argc) {
		if (argv[_argn][0] != '-') {
			break;
		}
		if (0 == strcmp("--", argv[_argn])) {
			_argn++;
			break;
		}
		optstr = argv[_argn]+1;
		if (*optstr == '-') optstr++;
		option = find_option(options, optstr);
		if (option == NULL) {
			if (argn) *argn = _argn;
			return XCONFIG_BAD_OPTION;
		}
		if (option->type == XCONFIG_BOOL
				|| option->type == XCONFIG_CALL_0) {
			set_option(option, NULL);
			_argn++;
			continue;
		}
		if ((_argn + 1) >= argc) {
			if (argn) *argn = _argn;
			return XCONFIG_MISSING_ARG;
		}
		set_option(option, argv[_argn+1]);
		_argn += 2;
	}
	if (argn) *argn = _argn;
	return XCONFIG_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
testq %rcx, %rcx
je 0x85d7
movl (%rbx), %r12d
jmp 0x85dd
movl $0x1, %r12d
cmpl %ebp, %r12d
jge 0x865b
movslq %r12d, %rax
movq (%r14,%rax,8), %r13
cmpb $0x2d, (%r13)
jne 0x865b
leaq 0x1334(%rip), %rdi      # 0x992b
movq %r13, %rsi
callq 0x3310
testl %eax, %eax
je 0x8658
cmpb $0x2d, 0x1(%r13)
je 0x860f
incq %r13
jmp 0x8613
addq $0x2, %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x8372
testq %rax, %rax
je 0x8674
testl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
jne 0x8635
movl $0x1, %r13d
xorl %esi, %esi
jmp 0x864b
leal 0x1(%r12), %ecx
cmpl %ebp, %ecx
jge 0x867b
movslq %ecx, %rcx
movq (%r14,%rcx,8), %rsi
movl $0x2, %r13d
movq %rax, %rdi
callq 0x83a8
addl %r13d, %r12d
jmp 0x85dd
incl %r12d
xorl %eax, %eax
testq %rbx, %rbx
je 0x8665
movl %r12d, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
jmp 0x865d
movl $0x2, %eax
jmp 0x865d
// File: /workspace/github_c_makefile_star2_O1/giometti[P]mastering_UNIX_programming/chapter_02/async.c
// Function: main
int main(void)
{
	int fd, n;
	char buf[MAX_SIZE];
	int ret;

	ret = open("data.bin", O_WRONLY | O_CREAT,
			S_IWUSR);
	if (ret < 0) {
		perror("open");
		return -1;
	}
	fd = ret;

	for (n = 0; n < 128; n++) {
		ret = write(fd, buf, n);
		if (ret < 0) {
			perror("write");
			return -1;
		}
	}

	close(fd);

	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
leaq 0xe65(%rip), %rdi       # 0x2004
movl $0x41, %esi
movl $0x80, %edx
xorl %eax, %eax
callq 0x1070
testl %eax, %eax
js 0x11ef
movl %eax, %ebx
xorl %r14d, %r14d
movq %rsp, %r15
movl %ebx, %edi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1040
testl %eax, %eax
js 0x11f8
incq %r14
cmpq $0x80, %r14
jne 0x11bc
movl %ebx, %edi
callq 0x1050
xorl %eax, %eax
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r14
popq %r15
retq
leaq 0xe17(%rip), %rdi       # 0x200d
jmp 0x11ff
leaq 0xe13(%rip), %rdi       # 0x2012
callq 0x1080
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x11e2
nop
// File: /workspace/github_c_makefile_star2_O1/cktan[P]tomlc99/toml_json.c
// Function: cat
static void cat(FILE *fp) {
  char errbuf[200];

  toml_table_t *tab = toml_parse_file(fp, errbuf, sizeof(errbuf));
  if (!tab) {
    fprintf(stderr, "ERROR: %s\n", errbuf);
    exit(1);
  }

  print_table(tab);
  printf("\n");

  toml_free(tab);
}

// Assembly:
pushq %rbx
subq $0xd0, %rsp
movq %rsp, %rsi
movl $0xc8, %edx
callq 0x3135
testq %rax, %rax
je 0x1493
movq %rax, %rbx
movq %rax, %rdi
callq 0x149b
movl $0xa, %edi
callq 0x1040
movq %rbx, %rdi
callq 0x3130
addq $0xd0, %rsp
popq %rbx
retq
movq %rsp, %rdi
callq 0x126d
// File: /workspace/github_c_makefile_star2_O1/cktan[P]tomlc99/toml_json.c
// Function: print_table
static void print_table(toml_table_t *curtab) {
  int i;
  const char *key;
  const char *raw;
  toml_array_t *arr;
  toml_table_t *tab;

  printf("{");
  for (i = 0; 0 != (key = toml_key_in(curtab, i)); i++) {

    printf("%s\"", i > 0 ? "," : "");
    print_escape_string(key);
    printf("\":");

    if (0 != (raw = toml_raw_in(curtab, key))) {
      print_raw(raw);
    } else if (0 != (arr = toml_array_in(curtab, key))) {
      print_array(arr);
    } else if (0 != (tab = toml_table_in(curtab, key))) {
      print_table(tab);
    } else {
      abort();
    }
  }
  printf("}");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl $0x7b, %edi
callq 0x1040
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3423
testq %rax, %rax
je 0x1574
movq %rax, %r12
movl $0x1, %ebp
leaq 0x4b91(%rip), %r13      # 0x6066
leaq 0x4b86(%rip), %r14      # 0x6062
leaq 0x4b85(%rip), %r15      # 0x6068
cmpl $0x1, %ebp
movq %r13, %rsi
leaq 0x521f(%rip), %rax      # 0x670f
cmoveq %rax, %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x10e0
movq %r12, %rdi
callq 0x1591
movq %r15, %rdi
xorl %eax, %eax
callq 0x10e0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x34fe
testq %rax, %rax
je 0x152a
movq %rax, %rdi
callq 0x1630
jmp 0x155c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3556
testq %rax, %rax
je 0x1544
movq %rax, %rdi
callq 0x184b
jmp 0x155c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x359d
testq %rax, %rax
je 0x158c
movq %rax, %rdi
callq 0x149b
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3423
movq %rax, %r12
incl %ebp
testq %rax, %rax
jne 0x14e3
movl $0x7d, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1040
callq 0x1050
// File: /workspace/github_c_makefile_star2_O1/cktan[P]tomlc99/toml_json.c
// Function: print_escape_string
static void print_escape_string(const char *s) {
  for (; *s; s++) {
    int ch = *s;
    switch (ch) {
    case '\b':
      printf("\\b");
      break;
    case '\t':
      printf("\\t");
      break;
    case '\n':
      printf("\\n");
      break;
    case '\f':
      printf("\\f");
      break;
    case '\r':
      printf("\\r");
      break;
    case '"':
      printf("\\\"");
      break;
    case '\\':
      printf("\\\\");
      break;
    default:
      printf("%c", ch);
      break;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x4a5e(%rip), %r12      # 0x6004
leaq 0x4ac1(%rip), %r13      # 0x606e
leaq 0x4abd(%rip), %rbp      # 0x6071
leaq 0x4ab9(%rip), %r14      # 0x6074
leaq 0x4ab5(%rip), %r15      # 0x6077
jmp 0x160f
leaq 0x4aa0(%rip), %rdi      # 0x606b
jmp 0x1605
cmpl $0x22, %eax
je 0x15fe
cmpl $0x5c, %eax
jne 0x15e0
leaq 0x4a9f(%rip), %rdi      # 0x607d
jmp 0x1605
movsbl %al, %edi
callq 0x1040
jmp 0x160c
movq %r14, %rdi
jmp 0x1605
movq %r15, %rdi
jmp 0x1605
movq %rbp, %rdi
jmp 0x1605
movq %r13, %rdi
jmp 0x1605
leaq 0x4a75(%rip), %rdi      # 0x607a
xorl %eax, %eax
callq 0x10e0
incq %rbx
movzbl (%rbx), %eax
cmpq $0xd, %rax
ja 0x15cd
movslq (%r12,%rax,4), %rcx
addq %r12, %rcx
jmpq *%rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/cktan[P]tomlc99/toml_json.c
// Function: print_array
static void print_array(toml_array_t *curarr) {
  if (toml_array_kind(curarr) == 't') {
    print_table_array(curarr);
    return;
  }

  printf("[");

  const char *raw;
  toml_array_t *arr;
  toml_table_t *tab;

  const int n = toml_array_nelem(curarr);
  for (int i = 0; i < n; i++) {
    printf("%s", i > 0 ? "," : "");

    if (0 != (arr = toml_array_at(curarr, i))) {
      print_array(arr);
      continue;
    }

    if (0 != (tab = toml_table_at(curarr, i))) {
      print_table(tab);
      continue;
    }

    raw = toml_raw_at(curarr, i);
    if (raw) {
      print_raw(raw);
      continue;
    }

    fflush(stdout);
    fprintf(stderr, "ERROR: unable to decode value in array\n");
    exit(1);
  }

  printf("]");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x3600
movl %eax, %ebp
movl $0x5b, %edi
callq 0x1040
movq %rbx, %rdi
cmpb $0x74, %bpl
jne 0x18d5
xorl %esi, %esi
callq 0x365b
testq %rax, %rax
je 0x1964
movq %rax, %r14
movl $0x1, %ebp
leaq 0x4e7d(%rip), %r12      # 0x670f
leaq 0x47cd(%rip), %r13      # 0x6066
leaq 0x4a95(%rip), %r15      # 0x6335
cmpl $0x1, %ebp
movq %r13, %rsi
cmoveq %r12, %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x10e0
movq %r14, %rdi
callq 0x149b
movq %rbx, %rdi
movl %ebp, %esi
callq 0x365b
movq %rax, %r14
incl %ebp
testq %rax, %rax
jne 0x18a0
jmp 0x1964
callq 0x3617
testl %eax, %eax
jle 0x1964
movl %eax, %ebp
leaq 0x4e24(%rip), %r12      # 0x670f
leaq 0x4774(%rip), %r13      # 0x6066
leaq 0x4a3c(%rip), %r14      # 0x6335
xorl %r15d, %r15d
testl %r15d, %r15d
movq %r13, %rsi
cmoveq %r12, %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x10e0
movq %rbx, %rdi
movl %r15d, %esi
callq 0x363f
testq %rax, %rax
je 0x192a
movq %rax, %rdi
callq 0x184b
jmp 0x195c
movq %rbx, %rdi
movl %r15d, %esi
callq 0x365b
testq %rax, %rax
je 0x1944
movq %rax, %rdi
callq 0x149b
jmp 0x195c
movq %rbx, %rdi
movl %r15d, %esi
callq 0x35e4
testq %rax, %rax
je 0x197c
movq %rax, %rdi
callq 0x1630
incl %r15d
cmpl %r15d, %ebp
jne 0x18fc
movl $0x5d, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1040
callq 0x12b6
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: parse_intel_event
unsigned long parse_intel_event(char *description){
  char *desc = strdup(description);
  char *name,*val;
  unsigned long value;
  union intel_raw_cpu_format result;
  result.config = 0;
  
  for (name = strtok(desc,",\n");name;name = strtok(NULL,",\n")){
    if (val = strchr(name,'=')){ // expected format "desc=value"
      *val = 0; // null terminator for name
      val++;
      value = strtol(val,NULL,16);
      
      if (!strcmp(name,"event")){
	result.event = value;
      } else if (!strcmp(name,"umask")){
	result.umask = value;
      } else if (!strcmp(name,"cmask")){
	result.cmask = value;	
      } else if (!strcmp(name,"period")){
	// appears in some Intel perf list output, but not sure of purpose, ignore...
      } else {
	fatal("unimplemented %s in parse_intel_event\n",name);
      }
    }
  }
  debug2("parse_event(\"%s\") = %lx\n",description,result.config);
  
  return result.config;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
callq 0x32e0
leaq 0x878a(%rip), %rsi      # 0xc538
movq %rax, %rdi
callq 0x3270
xorl %ebx, %ebx
testq %rax, %rax
je 0x3eaf
movq %rax, %rbp
movq %r14, (%rsp)
leaq 0x8769(%rip), %r14      # 0xc538
leaq 0x8765(%rip), %r15      # 0xc53b
leaq 0x8764(%rip), %r12      # 0xc541
xorl %r13d, %r13d
movq %rbp, %rdi
movl $0x3d, %esi
callq 0x30d0
testq %rax, %rax
je 0x3e81
movb $0x0, (%rax)
incq %rax
movq %rax, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x31f0
movq %rax, %rbx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x31a0
testl %eax, %eax
je 0x3e65
movq %rbp, %rdi
movq %r12, %rsi
callq 0x31a0
testl %eax, %eax
je 0x3e71
movq %rbp, %rdi
leaq 0x8711(%rip), %rsi      # 0xc547
callq 0x31a0
testl %eax, %eax
je 0x3e99
movq %rbp, %rdi
leaq 0x8704(%rip), %rsi      # 0xc54d
callq 0x31a0
testl %eax, %eax
je 0x3e81
leaq 0x86fb(%rip), %rdi      # 0xc554
movq %rbp, %rsi
xorl %eax, %eax
callq 0x9161
jmp 0x3e81
movzbl %bl, %eax
andl $0xffffff00, %r13d      # imm = 0xFFFFFF00
jmp 0x3e7e
shll $0x8, %ebx
movzwl %bx, %eax
andl $0xffff00ff, %r13d      # imm = 0xFFFF00FF
orl %eax, %r13d
xorl %edi, %edi
movq %r14, %rsi
callq 0x3270
movq %rax, %rbp
testq %rax, %rax
jne 0x3de0
jmp 0x3ea8
shll $0x18, %ebx
andl $0xffffff, %r13d        # imm = 0xFFFFFF
orl %ebx, %r13d
jmp 0x3e81
movl %r13d, %ebx
movq (%rsp), %r14
leaq 0x86c5(%rip), %rdi      # 0xc57b
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x9701
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: parse_amd_event
unsigned long parse_amd_event(char *description){
  char *desc = strdup(description);
  char *name,*val;
  unsigned long value;
  union amd_raw_cpu_format result;
  struct stat statbuf;
  result.config = 0;
  
  for (name = strtok(desc,",\n");name;name = strtok(NULL,",\n")){
    if (val = strchr(name,'=')){ // expected format "desc=value"
      *val = 0; // null terminator for name
      val++;
      value = strtol(val,NULL,16);
      
      if (!strcmp(name,"event")){
	result.event = value;
	result.event2 = value>>8;
      } else if (!strcmp(name,"umask")){
	result.umask = value;
      } else if (!strcmp(name,"cmask")){
	result.cmask = value;
      } else if (!strcmp(name,"requires")){
	// the value encodes the name of the type field...
	debug("checking for %s\n",val);
	if (stat(val,&statbuf) ==-1){
	  fatal("%s not found, is the perf module for this device loaded in the kernel?\n");
	}
      } else {
	fatal("unimplemented %s in parse_amd_event\n",name);
      }
    }
  }
  debug2("parse_event(\"%s\") = %lx\n",description,result.config);
  
  return result.config;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, (%rsp)
callq 0x32e0
leaq 0x8642(%rip), %rsi      # 0xc538
movq %rax, %rdi
callq 0x3270
testq %rax, %rax
je 0x403b
movq %rax, %rbx
leaq 0x8627(%rip), %r15      # 0xc538
leaq 0x8623(%rip), %r12      # 0xc53b
xorl %r14d, %r14d
movq %rbx, %rdi
movl $0x3d, %esi
callq 0x30d0
testq %rax, %rax
je 0x3ff0
movq %rax, %rbp
movb $0x0, (%rax)
incq %rbp
movq %rbp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x31f0
movq %rax, %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x31a0
testl %eax, %eax
je 0x3fa7
movq %rbx, %rdi
leaq 0x85dc(%rip), %rsi      # 0xc541
callq 0x31a0
testl %eax, %eax
je 0x3fc8
movq %rbx, %rdi
leaq 0x85cf(%rip), %rsi      # 0xc547
callq 0x31a0
testl %eax, %eax
je 0x3fdc
movq %rbx, %rdi
leaq 0x8609(%rip), %rsi      # 0xc594
callq 0x31a0
testl %eax, %eax
je 0x4008
leaq 0x865b(%rip), %rdi      # 0xc5f6
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9161
jmp 0x3ff0
movzbl %r13b, %eax
movabsq $-0xf00000100, %rcx     # imm = 0xFFFFFFF0FFFFFF00
andq %rcx, %r14
orq %rax, %r14
andl $0xf00, %r13d           # imm = 0xF00
shlq $0x18, %r13
jmp 0x3fed
shll $0x8, %r13d
movzwl %r13w, %eax
andq $-0xff01, %r14          # imm = 0xFFFF00FF
orq %rax, %r14
jmp 0x3ff0
shll $0x18, %r13d
movabsq $-0xff000001, %rax      # imm = 0xFFFFFFFF00FFFFFF
andq %rax, %r14
orq %r13, %r14
xorl %edi, %edi
movq %r15, %rsi
callq 0x3270
movq %rax, %rbx
testq %rax, %rax
jne 0x3f1b
jmp 0x403e
leaq 0x858e(%rip), %rdi      # 0xc59d
movq %rbp, %rsi
xorl %eax, %eax
callq 0x9600
movq %rbp, %rdi
leaq 0x8(%rsp), %rsi
callq 0x31e0
cmpl $-0x1, %eax
jne 0x3ff0
leaq 0x857c(%rip), %rdi      # 0xc5ae
xorl %eax, %eax
callq 0x9161
jmp 0x3ff0
xorl %r14d, %r14d
leaq 0x8536(%rip), %rdi      # 0xc57b
movq (%rsp), %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x9701
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: setup_raw_events
int setup_raw_events(void){
  int i;
  struct raw_event *events;
  unsigned int num_events;
  switch(cpu_info->vendor){
  case VENDOR_AMD:
    events = amd_raw_events;
    num_events = sizeof(amd_raw_events)/sizeof(amd_raw_events[0]);
    for (i=0;i<num_events;i++){
      if (events[i].use & counter_mask)
	events[i].raw.config = parse_amd_event(events[i].description);
    }    
    break;
  case VENDOR_INTEL:
    events = intel_raw_events;
    num_events = sizeof(intel_raw_events)/sizeof(intel_raw_events[0]);
    for (i=0;i<num_events;i++){
      if (events[i].use & counter_mask)
	events[i].raw.config = parse_intel_event(events[i].description);
    }        
    break;
  default:
    warning("Unknown CPU, no events parsed\n");
    break;
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
leaq 0xf0ec(%rip), %rax      # 0x13160
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x1, %eax
je 0x40bd
cmpl $0x2, %eax
jne 0x40fb
movl $0x18, %ebx
leaq 0xd701(%rip), %r14      # 0x11790
leaq 0xd12e(%rip), %r15      # 0x111c4
movl (%r15), %eax
testl %eax, -0x4(%rbx,%r14)
je 0x40ae
movq -0x10(%rbx,%r14), %rdi
callq 0x3d94
movq %rax, (%rbx,%r14)
addq $0x20, %rbx
cmpq $0x2d8, %rbx            # imm = 0x2D8
jne 0x4096
jmp 0x40f5
movl $0x18, %ebx
leaq 0xd987(%rip), %r14      # 0x11a50
leaq 0xd0f4(%rip), %r15      # 0x111c4
movl (%r15), %eax
testl %eax, -0x4(%rbx,%r14)
je 0x40e8
movq -0x10(%rbx,%r14), %rdi
callq 0x3ed5
movq %rax, (%rbx,%r14)
addq $0x20, %rbx
cmpq $0x558, %rbx            # imm = 0x558
jne 0x40d0
popq %rbx
popq %r14
popq %r15
retq
leaq 0x8519(%rip), %rdi      # 0xc61b
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x935d
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: launch_child
int launch_child(int argc,char *const argv[],char *const envp[]){
  pid_t child;
  int len;
  char *p,*path;
  char pathbuf[1024];

  if (pipe(child_pipe) == -1) fatal("pipe creation failed\n");
  switch(child = fork()){
  case 0: // child
    if (treeflag){
      debug("ptrace(PTRACE_TRACEME,0)\n");
      ptrace(PTRACE_TRACEME,0,NULL,NULL);
    }
    close(child_pipe[1]); // close writing end
    read(child_pipe[0],pathbuf,sizeof(pathbuf)); // wait until the parent has written
    execve(argv[0],argv,envp);
    // if argv[0] fails, look in path
    path = strdup(getenv("PATH"));
    len = strlen(argv[0]);
    p = strtok(path,":\n");
    if (p){
      do {
	strncpy(pathbuf,p,sizeof(pathbuf)-len-2);
	strcat(pathbuf,"/");
	strcat(pathbuf,argv[0]);
	execve(pathbuf,argv,envp);
	p = strtok(NULL,":\n");
      } while (p);
      // exec failed
      return 1;
    }
    break;
  case -1:
    fatal("fork failed\n");
    return 1;
  default:
    // parent
    close(child_pipe[0]); // close reading end
    child_pid = child;
    is_still_running = 1;
    break;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movq %rdx, %rbx
movq %rsi, %r14
leaq 0xe000(%rip), %rdi      # 0x1212c
callq 0x3140
cmpl $-0x1, %eax
jne 0x4144
leaq 0x84fd(%rip), %rdi      # 0xc63a
xorl %eax, %eax
callq 0x9161
callq 0x3330
cmpl $-0x1, %eax
je 0x4247
movl %eax, %ebp
testl %eax, %eax
jne 0x425c
leaq 0xdf7d(%rip), %rax      # 0x120e0
cmpl $0x0, (%rax)
je 0x4185
leaq 0x84e1(%rip), %rdi      # 0xc650
xorl %eax, %eax
callq 0x9600
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3220
movl 0xdfa5(%rip), %edi      # 0x12130
callq 0x3130
movl 0xdf96(%rip), %edi      # 0x1212c
movq %rsp, %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x3160
movq (%r14), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x3180
leaq 0x84b2(%rip), %rdi      # 0xc66a
callq 0x3030
movq %rax, %rdi
callq 0x32e0
movq %rax, %r12
movq (%r14), %rdi
callq 0x30b0
movq %rax, %r15
leaq 0x8495(%rip), %rsi      # 0xc66f
movq %r12, %rdi
callq 0x3270
testq %rax, %rax
je 0x4277
movslq %r15d, %rcx
movl $0x3fe, %r15d           # imm = 0x3FE
subq %rcx, %r15
movq %rsp, %r12
leaq 0x846e(%rip), %r13      # 0xc66f
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x3050
movq %r12, %rdi
callq 0x30b0
movw $0x2f, (%rsp,%rax)
movq (%r14), %rsi
movq %r12, %rdi
callq 0x32a0
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x3180
xorl %edi, %edi
movq %r13, %rsi
callq 0x3270
testq %rax, %rax
jne 0x4201
jmp 0x4255
leaq 0x8424(%rip), %rdi      # 0xc672
xorl %eax, %eax
callq 0x9161
movl $0x1, %eax
jmp 0x4279
movl 0xdeca(%rip), %edi      # 0x1212c
callq 0x3130
movl %ebp, 0xdebb(%rip)      # 0x12128
movl $0x1, 0xdebd(%rip)      # 0x12134
xorl %eax, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: ptrace_setup
void ptrace_setup(pid_t child_pid){
  int status;
  
  debug("ptrace_setup\n");
  waitpid(child_pid,&status,0); // wait for an initial event from the PTRACE_TRACEME

  if (WIFEXITED(status)){
    fatal("child process exited unexpectedly\n");
  } else if (WIFSIGNALED(status)){
    fatal("child process signaled unexpectedly, signal = %d\n",
	  WSTOPSIG(status));
  }
  // set the ptrace event flags
  status = ptrace(PTRACE_SETOPTIONS,child_pid,0,
		  PTRACE_O_EXITKILL | // kill child if I exit
		  PTRACE_O_TRACESYSGOOD | // set 0x80 for syscall traps
		  PTRACE_O_TRACECLONE|PTRACE_O_TRACEFORK|PTRACE_O_TRACEVFORK|
		  PTRACE_O_TRACEEXIT); // exit(2)
  ptrace(trace_syscall?PTRACE_SYSCALL:PTRACE_CONT,child_pid,NULL,NULL); // let the child being
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x83e7(%rip), %rdi      # 0xc67f
xorl %eax, %eax
callq 0x9600
leaq 0x4(%rsp), %r14
movl %ebx, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x3240
movl (%r14), %eax
movl %eax, %ecx
andl $0x7f, %ecx
je 0x42de
shll $0x18, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
cmpl $0x2000000, %ecx        # imm = 0x2000000
jl 0x42ec
movzbl %ah, %esi
leaq 0x83db(%rip), %rdi      # 0xc6b0
xorl %eax, %eax
callq 0x9161
jmp 0x42ec
leaq 0x83a8(%rip), %rdi      # 0xc68d
xorl %eax, %eax
callq 0x9161
movl $0x4200, %edi           # imm = 0x4200
movl %ebx, %esi
xorl %edx, %edx
movl $0x10004f, %ecx         # imm = 0x10004F
xorl %eax, %eax
callq 0x3220
movl %eax, 0x4(%rsp)
leaq 0xdde0(%rip), %rax      # 0x120ec
cmpl $0x0, (%rax)
movl $0x7, %eax
movl $0x18, %edi
cmovel %eax, %edi
movl %ebx, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3220
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: ptrace_read_null_terminated_string
char *ptrace_read_null_terminated_string(pid_t pid,long addr){
  static char buffer[4096];
  char *bufptr = buffer;
  int i;
  int len = 0;
  long int result;
  do {
    result = ptrace(PTRACE_PEEKDATA,pid,addr,0);
    if ((result == -1) && (errno != 0)){
      error("ptrace_read_null_terminated_string, errno = %d - %s\n",errno,strerror(errno));
      return NULL;
    } else {
      ((unsigned int *) &bufptr[len])[0] = result;
    }
    if (bufptr[len] == '\0' ||
	bufptr[len+1] == '\0' ||
	bufptr[len+2] == '\0' ||
	bufptr[len+3] == '\0')
      break;
    len += sizeof(int);
    addr += sizeof(int);
  } while (len < 4096);
  return bufptr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movl %edi, %ebp
movl $0xfffffffc, %r13d      # imm = 0xFFFFFFFC
leaq 0xddf2(%rip), %rbx      # 0x12140
movl $0x2, %edi
movl %ebp, %esi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3220
movq %rax, %r15
cmpq $-0x1, %rax
jne 0x4377
callq 0x3040
movl (%rax), %r12d
testl %r12d, %r12d
jne 0x43bf
movl %r15d, (%rbx)
testb %r15b, %r15b
je 0x43a6
cmpb $0x0, 0x1(%rbx)
je 0x43a6
cmpb $0x0, 0x2(%rbx)
je 0x43a6
cmpb $0x0, 0x3(%rbx)
je 0x43a6
addq $0x4, %r14
addl $0x4, %r13d
addq $0x4, %rbx
cmpl $0xffc, %r13d           # imm = 0xFFC
jb 0x434e
leaq 0xdd93(%rip), %rbx      # 0x12140
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r12d, %edi
callq 0x32f0
leaq 0x8314(%rip), %rdi      # 0xc6e2
xorl %ebx, %ebx
movl %r12d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9256
jmp 0x43ad
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: perf_event_open
int perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
		    int cpu, int group_fd, unsigned long flags){
  int ret;
  ret = syscall(__NR_perf_event_open, hw_event, pid, cpu, group_fd, flags);
  
  debug2("perf_event_open(event=<type=%d, config=%lx, format=%x, size=%d, disabled=%d>, pid=%d, cpu=%d, group_fd=%d, flags=%x) = %d\n",
	hw_event->type,hw_event->config, hw_event->read_format, hw_event->size, hw_event->disabled,
	 pid,cpu,group_fd,flags,ret);

  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r12
movl %ecx, %r15d
movl %edx, %r14d
movl %esi, %ebx
movq %rdi, %rbp
movl $0x12a, %edi            # imm = 0x12A
movq %rbp, %rsi
movl %ebx, %edx
movl %r14d, %ecx
movl %r15d, %r8d
movq %r12, %r9
xorl %eax, %eax
callq 0x31d0
movq %rax, %r13
movq 0x8(%rbp), %rdx
movq 0x20(%rbp), %rcx
movl (%rbp), %esi
movl 0x4(%rbp), %r8d
movl 0x28(%rbp), %r9d
andl $0x1, %r9d
subq $0x8, %rsp
leaq 0x7d31(%rip), %rdi      # 0xc8bd
xorl %eax, %eax
pushq %r13
pushq %r12
pushq %r15
pushq %r14
pushq %rbx
callq 0x9701
addq $0x30, %rsp
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: software_counter_group
struct counter_group *software_counter_group(char *name){
  int i;
  
  struct software_counters {
    char *label;
    unsigned int config;
  } sw_counters[] = {
    { "cpu-clock", PERF_COUNT_SW_CPU_CLOCK },
    { "task-clock", PERF_COUNT_SW_TASK_CLOCK },    
    { "page faults", PERF_COUNT_SW_PAGE_FAULTS },
    { "context switches", PERF_COUNT_SW_CONTEXT_SWITCHES },
    { "cpu migrations", PERF_COUNT_SW_CPU_MIGRATIONS },
    { "major page faults", PERF_COUNT_SW_PAGE_FAULTS_MAJ },
    { "minor page faults", PERF_COUNT_SW_PAGE_FAULTS_MIN },
    { "alignment faults", PERF_COUNT_SW_ALIGNMENT_FAULTS },
    { "emulation faults", PERF_COUNT_SW_EMULATION_FAULTS },
  };
  
  struct counter_group *cgroup = calloc(1,sizeof(struct counter_group));
  cgroup->label = strdup(name);
  cgroup->type_id = PERF_TYPE_SOFTWARE;
  cgroup->ncounters = sizeof(sw_counters)/sizeof(sw_counters[0]);
  cgroup->cinfo = calloc(cgroup->ncounters,sizeof(struct counter_info));
  for (i=0;i<cgroup->ncounters;i++){
    cgroup->cinfo[i].label = strdup(sw_counters[i].label);
    cgroup->cinfo[i].config = sw_counters[i].config;
  }
  return cgroup;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movl $0x1, %edi
movl $0x28, %esi
callq 0x3190
movq %rax, %rbx
movq %r14, %rdi
callq 0x32e0
movq %rax, (%rbx)
movabsq $0x900000001, %rax      # imm = 0x900000001
movq %rax, 0x8(%rbx)
movl $0x9, %edi
movl $0x58, %esi
callq 0x3190
movq %rax, %r14
movq %rax, 0x18(%rbx)
movl $0x8, %r15d
leaq 0xc0e5(%rip), %r12      # 0x10cf0
movq -0x8(%r15,%r12), %rdi
callq 0x32e0
movq %rax, (%r14)
movl (%r15,%r12), %eax
movq %rax, 0x18(%r14)
addq $0x58, %r14
addq $0x10, %r15
cmpq $0x98, %r15
jne 0x4c0b
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: generic_hardware_counter_group
struct counter_group *generic_hardware_counter_group(char *name){
  int i;
  
  struct hardware_counters {
    char *label;
    unsigned int config;
  } hw_counters[] = {
    { "cpu-cycles", PERF_COUNT_HW_CPU_CYCLES },
    { "instructions", PERF_COUNT_HW_INSTRUCTIONS },
    { "branches", PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
    { "branch-misses", PERF_COUNT_HW_BRANCH_MISSES },
  };
  
  struct counter_group *cgroup = calloc(1,sizeof(struct counter_group));
  cgroup->label = strdup(name);
  cgroup->type_id = PERF_TYPE_HARDWARE;
  cgroup->ncounters = sizeof(hw_counters)/sizeof(hw_counters[0]);
  cgroup->cinfo = calloc(cgroup->ncounters,sizeof(struct counter_info));
  for (i=0;i<cgroup->ncounters;i++){
    cgroup->cinfo[i].label = strdup(hw_counters[i].label);
    cgroup->cinfo[i].config = hw_counters[i].config;
  }
  return cgroup;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movl $0x1, %edi
movl $0x28, %esi
callq 0x3190
movq %rax, %rbx
movq %r14, %rdi
callq 0x32e0
movq %rax, (%rbx)
movabsq $0x400000000, %rax      # imm = 0x400000000
movq %rax, 0x8(%rbx)
movl $0x4, %edi
movl $0x58, %esi
callq 0x3190
movq %rax, %r14
movq %rax, 0x18(%rbx)
xorl %r15d, %r15d
leaq 0xc0ea(%rip), %r12      # 0x10d80
movq (%r15,%r12), %rdi
callq 0x32e0
movq %rax, (%r14)
movl 0x8(%r15,%r12), %eax
movq %rax, 0x18(%r14)
addq $0x58, %r14
addq $0x10, %r15
cmpq $0x40, %r15
jne 0x4c96
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: cache_counter_group
struct counter_group *cache_counter_group(char *name,unsigned int mask){
  int i;
  int ncounters = 0;
  int num_counters_available = (nmi_running)?5:6;
  struct counter_group *cgroup = NULL;
  
  for (i=0;i<sizeof(cache_events)/sizeof(cache_events[0]);i++){
    if (mask & cache_events[i].use) ncounters++;
  }
  if (ncounters == 0) return NULL;
  cgroup = calloc(1,sizeof(struct counter_group));
  cgroup->label = strdup("cache");
  cgroup->type_id = PERF_TYPE_HW_CACHE;  
  cgroup->ncounters = ncounters;
  cgroup->cinfo = calloc(cgroup->ncounters,sizeof(struct counter_info));
  cgroup->mask = mask;

  int count = 0;
  unsigned int group_id = -1;
  for (i=0;i<sizeof(cache_events)/sizeof(cache_events[0]);i++){
    if (mask & cache_events[i].use){
      cgroup->cinfo[count].label = cache_events[i].name;
      cgroup->cinfo[count].config = cache_events[i].config;
      if (cpu_info->vendor == VENDOR_AMD){
	if ((count % num_counters_available) == 0)
	  cgroup->cinfo[count].is_group_leader = 1;
      }
      count++;
    }
  }
  return cgroup;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
xorl %r13d, %r13d
movl $0x1c, %ecx
movl 0xd43d(%rip), %eax      # 0x12120
leaq 0xd2a6(%rip), %r12      # 0x11f90
movl (%rcx,%r12), %edx
andl %ebx, %edx
cmpl $0x1, %edx
sbbl $-0x1, %r13d
addq $0x20, %rcx
cmpq $0x13c, %rcx            # imm = 0x13C
jne 0x4cea
xorl %r14d, %r14d
cmpl $0x1, %eax
movl $0x0, %ebp
adcl $0x5, %ebp
testl %r13d, %r13d
je 0x4db6
movl $0x1, %edi
movl $0x28, %esi
callq 0x3190
movq %rax, %r15
leaq 0x7cfa(%rip), %rdi      # 0xca2e
callq 0x32e0
movq %rax, (%r15)
movl $0x3, 0x8(%r15)
movl %r13d, 0xc(%r15)
movl %r13d, %edi
movl $0x58, %esi
callq 0x3190
movq %rax, %rcx
movq %rax, 0x18(%r15)
movl %ebx, 0x10(%r15)
leaq 0xe3f9(%rip), %rax      # 0x13160
movq (%rax), %rsi
movl $0x1c, %edi
testl %ebx, (%rdi,%r12)
je 0x4da7
movq -0x14(%rdi,%r12), %rax
movslq %r14d, %rdx
imulq $0x58, %rdx, %r8
movq %rax, (%rcx,%r8)
movq -0xc(%rdi,%r12), %rax
movq %rax, 0x18(%rcx,%r8)
cmpl $0x1, (%rsi)
jne 0x4da4
movl %r14d, %eax
cltd
idivl %ebp
testl %edx, %edx
jne 0x4da4
orb $0x1, 0xc(%rcx,%r8)
incl %r14d
addq $0x20, %rdi
cmpq $0x13c, %rdi            # imm = 0x13C
jne 0x4d6f
jmp 0x4db9
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/mvermeulen[P]wspy/topdown.c
// Function: raw_counter_group
struct counter_group *raw_counter_group(char *name,unsigned int mask){
  int i;
  int available_counters = (nmi_running)?5:6;
  
  struct raw_event *events;
  unsigned int num_events;
  switch(cpu_info->vendor){
  case VENDOR_AMD:
    events = amd_raw_events;
    num_events = sizeof(amd_raw_events)/sizeof(amd_raw_events[0]);
    break;
  case VENDOR_INTEL:
    events = intel_raw_events;
    num_events = sizeof(intel_raw_events)/sizeof(intel_raw_events[0]);
    break;
  default:
    return NULL;
  }

  int num_counters = 0;
  for (i=0;i<num_events;i++){
    if (events[i].use & mask) num_counters++;
  }
  
  struct counter_group *cgroup = calloc(1,sizeof(struct counter_group));  
  cgroup->label = strdup(name);
  cgroup->type_id = PERF_TYPE_RAW;
  cgroup->ncounters = num_counters;
  cgroup->cinfo = calloc(cgroup->ncounters,sizeof(struct counter_info));
  cgroup->mask = mask;
  int count = 0;
  for (i=0;i<num_events;i++){
    if (events[i].use & mask){
      cgroup->cinfo[count].label = events[i].name;
      cgroup->cinfo[count].config = events[i].raw.config;
      cgroup->cinfo[count].device_type = events[i].device_type;
      // chunk into multiplex groups if needed
      if (cpu_info->vendor == VENDOR_AMD){
	if (((count % available_counters) == 0) || (events[i].device_type != PERF_TYPE_RAW))
	  cgroup->cinfo[count].is_group_leader = 1;
      }
      count++;
    }
  }
  
  return cgroup;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
xorl %r15d, %r15d
cmpl $0x1, 0xd33e(%rip)      # 0x12120
movl $0x0, %ebp
adcl $0x5, %ebp
leaq 0xe36f(%rip), %rax      # 0x13160
movq (%rax), %rax
movl (%rax), %eax
cmpl $0x1, %eax
je 0x4e13
cmpl $0x2, %eax
jne 0x4eea
movl $0x16, %r12d
leaq 0xc97f(%rip), %r13      # 0x11790
jmp 0x4e20
movl $0x2a, %r12d
leaq 0xcc30(%rip), %r13      # 0x11a50
movq %rdi, (%rsp)
movl %r12d, %eax
shll $0x5, %eax
xorl %ecx, %ecx
movl 0x14(%r13,%rcx), %edx
andl %ebx, %edx
cmpl $0x1, %edx
sbbl $-0x1, %r15d
addq $0x20, %rcx
cmpq %rcx, %rax
jne 0x4e2c
movl $0x1, %edi
movl $0x28, %esi
callq 0x3190
movq %rax, %r14
movq (%rsp), %rdi
callq 0x32e0
movq %rax, (%r14)
movl $0x4, 0x8(%r14)
movl %r15d, 0xc(%r14)
movl %r15d, %edi
movl $0x58, %esi
callq 0x3190
movq %rax, %rcx
movq %rax, 0x18(%r14)
movl %ebx, 0x10(%r14)
leaq 0xe2d4(%rip), %rax      # 0x13160
movq (%rax), %rdi
shll $0x5, %r12d
xorl %r8d, %r8d
xorl %esi, %esi
testl %ebx, 0x14(%r13,%r8)
je 0x4edf
movq (%r13,%r8), %rax
movslq %esi, %rdx
imulq $0x58, %rdx, %r9
movq %rax, (%rcx,%r9)
movq 0x18(%r13,%r8), %rax
movq %rax, 0x18(%rcx,%r9)
movl 0x10(%r13,%r8), %r10d
movl %r10d, 0x10(%rcx,%r9)
cmpl $0x1, (%rdi)
jne 0x4edd
movl %esi, %eax
cltd
idivl %ebp
testl %edx, %edx
je 0x4ed7
cmpl $0x4, %r10d
je 0x4edd
orb $0x1, 0xc(%rcx,%r9)
incl %esi
addq $0x20, %r8
cmpq %r8, %r12
jne 0x4e98
jmp 0x4eed
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq