#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*/ bar(char *, char *);
int /*<<< orphan*/ baz(char *, char *, int, char *);
int /*<<< orphan*/ foo(char *, char *);
scalar_t__ strlen(char *);
void test(char *w, int x, char *y, char *z) {
  char *p, b[32];
  for (p = y; *p; p += strlen(p) + 1) {
    baz(w, p, x, z);
    foo("msg1 %s", b);
  }
  for (p = y; *p; p += strlen(p) + 1)
    bar(" %s", p);
  foo("msg2 %s", b);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11aa <test+0x6a>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <baz@plt>
lea    -0x50(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1060 <foo@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    115f <test+0x1f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e9 <test+0xa9>
mov    -0x28(%rbp),%rsi
lea    0xe3a(%rip),%rdi
call   1040 <bar@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11b2 <test+0x72>
lea    -0x50(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1060 <foo@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmpb   $0x0,(%rdx)
je     11e0 <test+0xa0>
mov    %rcx,%r14
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%rbp
mov    %rsp,%r13
mov    %rdx,%rbx
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
call   1030 <baz@plt>
lea    0xe78(%rip),%rdi
mov    %r13,%rsi
call   1060 <foo@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmpb   $0x0,0x1(%rax,%rbx,1)
lea    0x1(%rax,%rbx,1),%rbx
jne    1170 <test+0x30>
cmpb   $0x0,(%r12)
je     11e0 <test+0xa0>
lea    0xe52(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <bar@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
cmpb   $0x0,0x1(%rax,%r12,1)
lea    0x1(%rax,%r12,1),%r12
jne    11c0 <test+0x80>
lea    0xe21(%rip),%rdi
mov    %rsp,%rsi
call   1060 <foo@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"msg1 %s\00"
@.str.1 = [4 x i8] c" %s\00"
@.str.2 = [8 x i8] c"msg2 %s\00"
define void @test(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [32 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i8*, i8** %7
store i8* %11, i8** %9
br label %12
12: ; preds = %24, %4
%13 = load i8*, i8** %9
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i8*, i8** %9
%19 = load i32, i32* %6
%20 = load i8*, i8** %8
%21 = call i32 @baz(i8* %17, i8* %18, i32 %19, i8* %20)
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%23 = call i32 @foo(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %16
%25 = load i8*, i8** %9
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = load i8*, i8** %9
%29 = getelementptr inbounds i8, i8* %28, i64 %27
store i8* %29, i8** %9
br label %12
30: ; preds = %12
%31 = load i8*, i8** %7
store i8* %31, i8** %9
br label %32
32: ; preds = %39, %30
%33 = load i8*, i8** %9
%34 = load i8, i8* %33
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i8*, i8** %9
%38 = call i32 @bar(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36
%40 = load i8*, i8** %9
%41 = call i64 @strlen(i8* %40)
%42 = add nsw i64 %41, 1
%43 = load i8*, i8** %9
%44 = getelementptr inbounds i8, i8* %43, i64 %42
store i8* %44, i8** %9
br label %32
45: ; preds = %32
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%47 = call i32 @foo(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %46)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"msg1 %s\00"
@.str.1 = [4 x i8] c" %s\00"
@.str.2 = [8 x i8] c"msg2 %s\00"
define void @test(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 0
br i1 %8, label %29, label %12
9: ; preds = %12
%10 = load i8, i8* %2
%11 = icmp eq i8 %10, 0
br i1 %11, label %29, label %21
12: ; preds = %4, %12
%13 = phi i8* [ %18, %12 ], [ %2, %4 ]
%14 = call i32 @baz(i8* %0, i8* %13, i32 %1, i8* %3)
%15 = call i32 @foo(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %6)
%16 = call i64 @strlen(i8* %13)
%17 = add nsw i64 %16, 1
%18 = getelementptr inbounds i8, i8* %13, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %9, label %12
21: ; preds = %9, %21
%22 = phi i8* [ %26, %21 ], [ %2, %9 ]
%23 = call i32 @bar(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i64 @strlen(i8* %22)
%25 = add nsw i64 %24, 1
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %21
29: ; preds = %21, %4, %9
%30 = call i32 @foo(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %6)
ret void
}