#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*/ fprintf(int /*<<< orphan*/, char *, char const *const,
                           char *);
int /*<<< orphan*/ printf(char *, char const *const, int);
int /*<<< orphan*/ stderr;
int test_strlen(char const *const, int);
void doit(const char *const s) {
  printf("strlen(\"%s\")=%d\n", s, test_strlen(s, 1));
  fprintf(stderr, "strlen(\"%s\")=%s\n", s,
          test_strlen(s, 0) ? "true" : "false");
}


x86 assembly (clang, -O0):
<doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1030 <test_strlen@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <test_strlen@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    %eax,%esi
lea    0xe94(%rip),%rcx
lea    0xe88(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doit>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x1,%esi
call   1030 <test_strlen@plt>
lea    0xeb9(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <test_strlen@plt>
test   %eax,%eax
lea    0xeba(%rip),%rax
lea    0xeae(%rip),%rcx
cmove  %rax,%rcx
lea    0xe92(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"strlen(\22%s\22)=%d\0A\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"strlen(\22%s\22)=%s\0A\00"
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [6 x i8] c"false\00"
define void @doit(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @test_strlen(i8* %4, i32 1)
%6 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %5)
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @test_strlen(i8* %9, i32 0)
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%14 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %13)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"strlen(\22%s\22)=%d\0A\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"strlen(\22%s\22)=%s\0A\00"
@.str.2 = [5 x i8] c"true\00"
@.str.3 = [6 x i8] c"false\00"
define void @doit(i8* %0) {
%2 = tail call i32 @test_strlen(i8* %0, i32 1)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2)
%4 = load i32, i32* @stderr
%5 = tail call i32 @test_strlen(i8* %0, i32 0)
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%8 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %7)
ret void
}