#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 */
scalar_t__ get_last_node_with_offset(int *, int);
void append_ll(void *head, void *rec, int offset) {
  int *deref2, deref, *lrec = (int *)rec, *ptr, **lhead = (int **)head;
  ptr = (int *)get_last_node_with_offset(*lhead, offset);
  if (!ptr) {
    deref2 = (int *)((int)lrec + offset);
    *deref2 = 0;
    *lhead = lrec;
    return;
  }
  deref2 = (int *)((int)ptr + offset);
  *deref2 = (int)lrec;
}


x86 assembly (clang, -O0):
<append_ll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
call   1030 <get_last_node_with_offset@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1178 <append_ll+0x68>
mov    -0x30(%rbp),%rax
add    -0x14(%rbp),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,(%rax)
jmp    1191 <append_ll+0x81>
mov    -0x38(%rbp),%rax
add    -0x14(%rbp),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_ll>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
mov    %edx,%esi
call   1030 <get_last_node_with_offset@plt>
test   %rax,%rax
je     1136 <append_ll+0x26>
cltq
movslq %ebp,%rcx
mov    %r14d,(%rax,%rcx,1)
jmp    1146 <append_ll+0x36>
movslq %r14d,%rax
movslq %ebp,%rcx
movl   $0x0,(%rax,%rcx,1)
mov    %r14,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @append_ll(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32**
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
%13 = bitcast i8* %12 to i32*
store i32* %13, i32** %9
%14 = load i8*, i8** %4
%15 = bitcast i8* %14 to i32**
store i32** %15, i32*** %11
%16 = load i32**, i32*** %11
%17 = load i32*, i32** %16
%18 = load i32, i32* %6
%19 = call i64 @get_last_node_with_offset(i32* %17, i32 %18)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %10
%21 = load i32*, i32** %10
%22 = icmp ne i32* %21, null
br i1 %22, label %33, label %23
23: ; preds = %3
%24 = load i32*, i32** %9
%25 = ptrtoint i32* %24 to i32
%26 = load i32, i32* %6
%27 = add nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
store i32* %29, i32** %7
%30 = load i32*, i32** %7
store i32 0, i32* %30
%31 = load i32*, i32** %9
%32 = load i32**, i32*** %11
store i32* %31, i32** %32
br label %43
33: ; preds = %3
%34 = load i32*, i32** %10
%35 = ptrtoint i32* %34 to i32
%36 = load i32, i32* %6
%37 = add nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = inttoptr i64 %38 to i32*
store i32* %39, i32** %7
%40 = load i32*, i32** %9
%41 = ptrtoint i32* %40 to i32
%42 = load i32*, i32** %7
store i32 %41, i32* %42
br label %43
43: ; preds = %33, %23
ret void
}

LLVM IR (-O2):
define void @append_ll(i8* nocapture %0, i8* %1, i32 %2) {
%4 = bitcast i8* %0 to i32**
%5 = load i32*, i32** %4
%6 = tail call i64 @get_last_node_with_offset(i32* %5, i32 %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %3
%9 = ptrtoint i8* %1 to i64
%10 = trunc i64 %9 to i32
%11 = add nsw i32 %10, %2
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
store i32 0, i32* %13
%14 = bitcast i8* %0 to i8**
store i8* %1, i8** %14
br label %22
15: ; preds = %3
%16 = trunc i64 %6 to i32
%17 = add nsw i32 %16, %2
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = ptrtoint i8* %1 to i64
%21 = trunc i64 %20 to i32
store i32 %21, i32* %19
br label %22
22: ; preds = %15, %8
ret void
}