#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__ strcmp(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int test_builtin_calls_me(void) {
  char *null1 = 0;
  char *null2 = null1;
  char *null3 = null2;
  int r = 0;
  r += strcmp(null1, "123");
  r += strncmp("2345", null2, 4);
  r += strlen(null3);
  return r;
}


x86 assembly (clang, -O0):
<test_builtin_calls_me>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_builtin_calls_me>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rsi
xor    %edi,%edi
call   1050 <strcmp@plt>
mov    %rax,%r14
lea    0xeb8(%rip),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rbx
add    %r14d,%ebx
xor    %edi,%edi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"123\00"
@.str.1 = [5 x i8] c"2345\00"
define i32 @test_builtin_calls_me() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* null, i8** %1
%5 = load i8*, i8** %1
store i8* %5, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
store i32 0, i32* %4
%7 = load i8*, i8** %1
%8 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = add nsw i64 %10, %8
%12 = trunc i64 %11 to i32
store i32 %12, i32* %4
%13 = load i8*, i8** %2
%14 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 4)
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = add nsw i64 %16, %14
%18 = trunc i64 %17 to i32
store i32 %18, i32* %4
%19 = load i8*, i8** %3
%20 = call i64 @strlen(i8* %19)
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = add nsw i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* %4
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@.str = [4 x i8] c"123\00"
@.str.1 = [5 x i8] c"2345\00"
define i32 @test_builtin_calls_me() {
%1 = tail call i64 @strcmp(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* null, i32 4)
%3 = add i64 %2, %1
%4 = tail call i64 @strlen(i8* dereferenceable(1) null)
%5 = add i64 %3, %4
%6 = trunc i64 %5 to i32
ret i32 %6
}