#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__ malloc(int);
int nb_elems(int **);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int **iptrs = (int **)malloc(3 * sizeof(int *));
  iptrs[0] = (int *)malloc(sizeof(int));
  *(iptrs[0]) = 42;
  iptrs[1] = (int *)malloc(sizeof(int));
  *(iptrs[1]) = 23;
  iptrs[2] = NULL;
  printf("%d", nb_elems(iptrs));
}


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

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

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32**
%2 = call i64 @malloc(i32 24)
%3 = inttoptr i64 %2 to i32**
store i32** %3, i32*** %1
%4 = call i64 @malloc(i32 4)
%5 = inttoptr i64 %4 to i32*
%6 = load i32**, i32*** %1
%7 = getelementptr inbounds i32*, i32** %6, i64 0
store i32* %5, i32** %7
%8 = load i32**, i32*** %1
%9 = getelementptr inbounds i32*, i32** %8, i64 0
%10 = load i32*, i32** %9
store i32 42, i32* %10
%11 = call i64 @malloc(i32 4)
%12 = inttoptr i64 %11 to i32*
%13 = load i32**, i32*** %1
%14 = getelementptr inbounds i32*, i32** %13, i64 1
store i32* %12, i32** %14
%15 = load i32**, i32*** %1
%16 = getelementptr inbounds i32*, i32** %15, i64 1
%17 = load i32*, i32** %16
store i32 23, i32* %17
%18 = load i32**, i32*** %1
%19 = getelementptr inbounds i32*, i32** %18, i64 2
store i32* null, i32** %19
%20 = load i32**, i32*** %1
%21 = call i32 @nb_elems(i32** %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 24)
%2 = inttoptr i64 %1 to i32**
%3 = tail call i64 @malloc(i32 4)
%4 = inttoptr i64 %3 to i32*
store i32* %4, i32** %2
store i32 42, i32* %4
%5 = tail call i64 @malloc(i32 4)
%6 = inttoptr i64 %5 to i32*
%7 = getelementptr inbounds i32*, i32** %2, i64 1
store i32* %6, i32** %7
store i32 23, i32* %6
%8 = getelementptr inbounds i32*, i32** %2, i64 2
store i32* null, i32** %8
%9 = tail call i32 @nb_elems(i32** %2)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
ret i32 0
}