#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*/ free(struct tcb *);
struct tcb *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  struct tcb {
    int counter;
    struct tcb *next;
  };
  struct tcb *test;
  test = malloc(sizeof(struct tcb));
  test->counter = 10;
  test->next = NULL;
  ++(test->counter);
  printf("counter = %d\n", test->counter);
  free(test);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0xa,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movq   $0x0,0x8(%rax)
movl   $0xb,(%rax)
lea    0xead(%rip),%rdi
mov    $0xb,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.tcb = type { i32, %struct.tcb* }
%struct.tcb.0 = type opaque
%struct.tcb.1 = type opaque
@.str = [14 x i8] c"counter = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.tcb*
store i32 0, i32* %1
%3 = call %struct.tcb.0* @malloc(i32 16)
%4 = bitcast %struct.tcb.0* %3 to %struct.tcb*
store %struct.tcb* %4, %struct.tcb** %2
%5 = load %struct.tcb*, %struct.tcb** %2
%6 = getelementptr inbounds %struct.tcb, %struct.tcb* %5, i32 0, i32 0
store i32 10, i32* %6
%7 = load %struct.tcb*, %struct.tcb** %2
%8 = getelementptr inbounds %struct.tcb, %struct.tcb* %7, i32 0, i32 1
store %struct.tcb* null, %struct.tcb** %8
%9 = load %struct.tcb*, %struct.tcb** %2
%10 = getelementptr inbounds %struct.tcb, %struct.tcb* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
store i32 %12, i32* %10
%13 = load %struct.tcb*, %struct.tcb** %2
%14 = getelementptr inbounds %struct.tcb, %struct.tcb* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load %struct.tcb*, %struct.tcb** %2
%18 = bitcast %struct.tcb* %17 to %struct.tcb.1*
%19 = call i32 @free(%struct.tcb.1* %18)
ret i32 0
}

LLVM IR (-O2):
%struct.tcb.0 = type opaque
%struct.tcb = type { i32, %struct.tcb* }
%struct.tcb.1 = type opaque
@.str = [14 x i8] c"counter = %d\0A\00"
define i32 @main() {
%1 = tail call %struct.tcb.0* @malloc(i32 16)
%2 = bitcast %struct.tcb.0* %1 to %struct.tcb*
%3 = bitcast %struct.tcb.0* %1 to i32*
%4 = getelementptr inbounds %struct.tcb, %struct.tcb* %2, i64 0, i32 1
store %struct.tcb* null, %struct.tcb** %4
store i32 11, i32* %3
%5 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 11)
%6 = bitcast %struct.tcb.0* %1 to %struct.tcb.1*
%7 = tail call i32 @free(%struct.tcb.1* %6)
ret i32 0
}