#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 */
char *memchr(char *, char, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *strchr(char *, char);
char *strdup(char *);
int strlen(char *);
char *strrchr(char *, char);
int main(void) {
  char *h = "hello, world";
  char *p = strdup(h);
  char u[20];
  char *c;
  int len;
  len = strlen(p);
  c = strchr(p, 'l');
  c = strchr(p, 'x');
  c = strrchr(p, 'l');
  c = strrchr(p, 'x');
  c = memchr(p, 'l', len);
  c = memchr(p, 'x', len);
  memcpy(u, p, len + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x6c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x78,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x6c,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x78,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    $0x6c,%esi
call   1060 <memchr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    $0x78,%esi
call   1060 <memchr@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x3c(%rbp),%edx
add    $0x1,%edx
call   1070 <memcpy@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xeb3(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x6c,%esi
mov    %eax,%edx
call   1040 <memchr@plt>
mov    %rbx,%rdi
mov    $0x78,%esi
mov    %ebp,%edx
call   1040 <memchr@plt>
add    $0x1,%ebp
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"hello, world\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [20 x i8]
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @strdup(i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i8*, i8** %3
%12 = call i8* @strchr(i8* %11, i8 signext 108)
store i8* %12, i8** %5
%13 = load i8*, i8** %3
%14 = call i8* @strchr(i8* %13, i8 signext 120)
store i8* %14, i8** %5
%15 = load i8*, i8** %3
%16 = call i8* @strrchr(i8* %15, i8 signext 108)
store i8* %16, i8** %5
%17 = load i8*, i8** %3
%18 = call i8* @strrchr(i8* %17, i8 signext 120)
store i8* %18, i8** %5
%19 = load i8*, i8** %3
%20 = load i32, i32* %6
%21 = call i8* @memchr(i8* %19, i8 signext 108, i32 %20)
store i8* %21, i8** %5
%22 = load i8*, i8** %3
%23 = load i32, i32* %6
%24 = call i8* @memchr(i8* %22, i8 signext 120, i32 %23)
store i8* %24, i8** %5
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
%29 = call i32 @memcpy(i8* %25, i8* %26, i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"hello, world\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = tail call dereferenceable_or_null(13) i8* @strdup(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %2)
%5 = tail call i8* @memchr(i8* %2, i8 signext 108, i32 %4)
%6 = tail call i8* @memchr(i8* %2, i8 signext 120, i32 %4)
%7 = add nsw i32 %4, 1
%8 = call i32 @memcpy(i8* %3, i8* %2, i32 %7)
ret i32 0
}