#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*/ printf(char *, char *, size_t);
size_t strnlen(char *, int);
int main(int argc, char *argv[]) {
  char str1[10] = "test";
  char *str2 = "testtesttest";
  size_t ret = strnlen(str1, 10);
  printf("strnlen(%s, 10) is %zu\n", str1, ret);
  ret = strnlen(str2, 10);
  printf("strnlen(%s, 10) is %zu\n", str2, ret);
  str2 = NULL;
  ret = strnlen(str2, 10);
  printf("strnlen(%s, 10) is %zu\n", str2, ret);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x1a(%rbp)
mov    0xec0(%rip),%ax
mov    %ax,-0x12(%rbp)
lea    0xeb7(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x1a(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strnlen@plt>
mov    %rax,-0x30(%rbp)
lea    -0x1a(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strnlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strnlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movw   $0x0,0x10(%rsp)
movq   $0x74736574,0x8(%rsp)
73 74
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strnlen@plt>
lea    0xec7(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
lea    0xea5(%rip),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strnlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %edi,%edi
mov    $0xa,%esi
call   1040 <strnlen@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.str1 = [10 x i8] c"test\00\00\00\00\00\00"
@.str = [13 x i8] c"testtesttest\00"
@.str.1 = [24 x i8] c"strnlen(%s, 10) is %zu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8]
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [10 x i8]* %6 to i8*
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %7
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%11 = call i64 @strnlen(i8* %10, i32 10)
store i64 %11, i64* %8
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%13 = load i64, i64* %8
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12, i64 %13)
%15 = load i8*, i8** %7
%16 = call i64 @strnlen(i8* %15, i32 10)
store i64 %16, i64* %8
%17 = load i8*, i8** %7
%18 = load i64, i64* %8
%19 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %17, i64 %18)
store i8* null, i8** %7
%20 = load i8*, i8** %7
%21 = call i64 @strnlen(i8* %20, i32 10)
store i64 %21, i64* %8
%22 = load i8*, i8** %7
%23 = load i64, i64* %8
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %22, i64 %23)
ret i32 0
}

LLVM IR (-O2):
@__const.main.str1 = [10 x i8] c"test\00\00\00\00\00\00"
@.str = [13 x i8] c"testtesttest\00"
@.str.1 = [24 x i8] c"strnlen(%s, 10) is %zu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = call i64 @strnlen(i8* %4, i32 10)
%6 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %4, i64 %5)
%7 = call i64 @strnlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 10)
%8 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = call i64 @strnlen(i8* null, i32 10)
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* null, i64 %9)
ret i32 0
}