#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ *strchr(char *, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
char *strcpy(char *, char *);
char const *const strpbrk(char const *const, char *);
int main(void) {
  int status;
  int errors = 0;
  char buf1[1000];
  char *cp;
  char ch;
  cp = strcpy(buf1, "hello world");
  if (strcmp("hello world", cp++) != 0) {
    puts("strcmp test 1 failed");
    ++errors;
  }
  cp = buf1;
  if (strcmp(cp++, "hello world") != 0) {
    puts("strcmp test 2 failed");
    ++errors;
  }
  ch = 'h';
  if (strchr("hello world", ch++) == NULL) {
    puts("strchr test 1 failed");
    ++errors;
  }
  const char *const hw = "hello world";
  if (strpbrk(hw, "o") - hw != 4) {
    puts("strpbrk test 1 failed");
    ++errors;
  }
  if (errors == 0) {
    status = EXIT_SUCCESS;
    puts("No errors.");
  } else {
    status = EXIT_FAILURE;
    printf("%d errors.\n", errors);
  }
  return status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x408(%rbp)
mov    -0x408(%rbp),%rsi
mov    %rsi,%rax
add    $0x1,%rax
mov    %rax,-0x408(%rbp)
lea    0xe51(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11d3 <main+0x73>
lea    0xe47(%rip),%rdi
call   1040 <puts@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    -0x400(%rbp),%rax
mov    %rax,-0x408(%rbp)
mov    -0x408(%rbp),%rdi
mov    %rdi,%rax
add    $0x1,%rax
mov    %rax,-0x408(%rbp)
lea    0xe03(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1221 <main+0xc1>
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movb   $0x68,-0x409(%rbp)
mov    -0x409(%rbp),%al
mov    %al,%cl
add    $0x1,%cl
mov    %cl,-0x409(%rbp)
movsbl %al,%esi
lea    0xdbd(%rip),%rdi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    1267 <main+0x107>
lea    0xddd(%rip),%rdi
call   1040 <puts@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xd92(%rip),%rax
mov    %rax,-0x418(%rbp)
lea    0xd84(%rip),%rdi
lea    0xdc8(%rip),%rsi
call   1080 <strpbrk@plt>
lea    0xd71(%rip),%rcx
sub    %rcx,%rax
cmp    $0x4,%rax
je     12b1 <main+0x151>
lea    0xdaa(%rip),%rdi
call   1040 <puts@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    12d8 <main+0x178>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
lea    0xd95(%rip),%rdi
call   1040 <puts@plt>
jmp    12f3 <main+0x193>
mov    0x2d01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
lea    0xd80(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x3e8,%rsp
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,(%rsp)
movl   $0x646c72,0x8(%rsp)
lea    0xe9a(%rip),%rdi
mov    %rsp,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1186 <main+0x46>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    1188 <main+0x48>
xor    %ebx,%ebx
lea    0xe71(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ab <main+0x6b>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%ebx
lea    0xe4e(%rip),%rdi
mov    $0x68,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11dc <main+0x9c>
test   %ebx,%ebx
jne    11eb <main+0xab>
mov    0x2e0c(%rip),%rax
mov    (%rax),%ebp
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
jmp    1202 <main+0xc2>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%ebx
mov    0x2dee(%rip),%rax
mov    (%rax),%ebp
lea    0xe5b(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [21 x i8] c"strcmp test 1 failed\00"
@.str.2 = [21 x i8] c"strcmp test 2 failed\00"
@.str.3 = [21 x i8] c"strchr test 1 failed\00"
@.str.4 = [2 x i8] c"o\00"
@.str.5 = [22 x i8] c"strpbrk test 1 failed\00"
@EXIT_SUCCESS = global i32 0
@.str.6 = [11 x i8] c"No errors.\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [12 x i8] c"%d errors.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %3
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%9 = call i8* @strcpy(i8* %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %5
%12 = call i64 @strcmp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %10)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %18
18: ; preds = %14, %0
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
%22 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %28
28: ; preds = %24, %18
store i8 104, i8* %6
%29 = load i8, i8* %6
%30 = add i8 %29, 1
store i8 %30, i8* %6
%31 = sext i8 %29 to i32
%32 = call i32* @strchr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %38
38: ; preds = %34, %28
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %7
%39 = call i8* @strpbrk(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%40 = ptrtoint i8* %39 to i64
%41 = sub i64 %40, ptrtoint ([12 x i8]* @.str to i64)
%42 = icmp ne i64 %41, 4
br i1 %42, label %43, label %47
43: ; preds = %38
%44 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %47
47: ; preds = %43, %38
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* @EXIT_SUCCESS
store i32 %51, i32* %2
%52 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %57
53: ; preds = %47
%54 = load i32, i32* @EXIT_FAILURE
store i32 %54, i32* %2
%55 = load i32, i32* %3
%56 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %53, %50
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [21 x i8] c"strcmp test 1 failed\00"
@.str.2 = [21 x i8] c"strcmp test 2 failed\00"
@.str.3 = [21 x i8] c"strchr test 1 failed\00"
@EXIT_SUCCESS = global i32 0
@.str.6 = [11 x i8] c"No errors.\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [12 x i8] c"%d errors.\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = call i64 @strcmp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = phi i32 [ 1, %5 ], [ 0, %0 ]
%9 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%13 = add nuw nsw i32 %8, 1
br label %14
14: ; preds = %11, %7
%15 = phi i32 [ %13, %11 ], [ %8, %7 ]
%16 = call i32* @strchr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 104)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%20 = add nuw nsw i32 %15, 1
br label %26
21: ; preds = %14
%22 = icmp eq i32 %15, 0
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* @EXIT_SUCCESS
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %30
26: ; preds = %18, %21
%27 = phi i32 [ %20, %18 ], [ %15, %21 ]
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %27)
br label %30
30: ; preds = %26, %23
%31 = phi i32 [ %24, %23 ], [ %28, %26 ]
ret i32 %31
}