#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*/ putchar(char);
int /*<<< orphan*/ sched_yield();
int strlen(char *);
void *thread_entry(void *ptr) {
  int i, j, len;
  char *str = (char *)ptr;
  len = strlen(str);
  for (i = 0; i < 10; i++) {
    for (j = 0; j < len; j++) {
      putchar(str[j]);
      sched_yield();
    }
    putchar('\n');
  }
}


x86 assembly (clang, -O0):
<thread_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11b2 <thread_entry+0x82>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    119a <thread_entry+0x6a>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    $0x0,%al
call   1050 <sched_yield@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1168 <thread_entry+0x38>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <thread_entry+0x27>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_entry>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
jle    131b <thread_entry+0x1eb>
mov    %eax,%r14d
mov    %eax,%r15d
xor    %ebp,%ebp
nop
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1150 <thread_entry+0x20>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    1325 <thread_entry+0x1f5>
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1180 <thread_entry+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    132f <thread_entry+0x1ff>
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11b0 <thread_entry+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    1339 <thread_entry+0x209>
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11e0 <thread_entry+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    1343 <thread_entry+0x213>
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1210 <thread_entry+0xe0>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    134d <thread_entry+0x21d>
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1240 <thread_entry+0x110>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    1357 <thread_entry+0x227>
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1270 <thread_entry+0x140>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    1361 <thread_entry+0x231>
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    12a0 <thread_entry+0x170>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    136b <thread_entry+0x23b>
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    12d0 <thread_entry+0x1a0>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    1375 <thread_entry+0x245>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <sched_yield@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1300 <thread_entry+0x1d0>
jmp    1375 <thread_entry+0x245>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
define i8* @thread_entry(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
store i32 0, i32* %4
br label %11
11: ; preds = %32, %1
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %35
14: ; preds = %11
store i32 0, i32* %5
br label %15
15: ; preds = %27, %14
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @putchar(i8 signext %24)
%26 = call i32 (...) @sched_yield()
br label %27
27: ; preds = %19
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %15
30: ; preds = %15
%31 = call i32 @putchar(i8 signext 10)
br label %32
32: ; preds = %30
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %11
35: ; preds = %11
%36 = load i8*, i8** %2
ret i8* %36
}

LLVM IR (-O2):
define noalias i8* @thread_entry(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @putchar(i8 signext 10)
br label %28
6: ; preds = %1
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %14, %8 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @putchar(i8 signext %11)
%13 = tail call i32 (...) @sched_yield()
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = tail call i32 @putchar(i8 signext 10)
br i1 %3, label %18, label %28
18: ; preds = %16
%19 = zext i32 %2 to i64
br label %20
20: ; preds = %20, %18
%21 = phi i64 [ 0, %18 ], [ %26, %20 ]
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @putchar(i8 signext %23)
%25 = tail call i32 (...) @sched_yield()
%26 = add nuw nsw i64 %21, 1
%27 = icmp eq i64 %26, %19
br i1 %27, label %30, label %20
28: ; preds = %4, %16
%29 = tail call i32 @putchar(i8 signext 10)
br label %42
30: ; preds = %20
%31 = tail call i32 @putchar(i8 signext 10)
br i1 %3, label %32, label %42
32: ; preds = %30
%33 = zext i32 %2 to i64
br label %34
34: ; preds = %34, %32
%35 = phi i64 [ 0, %32 ], [ %40, %34 ]
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
%38 = tail call i32 @putchar(i8 signext %37)
%39 = tail call i32 (...) @sched_yield()
%40 = add nuw nsw i64 %35, 1
%41 = icmp eq i64 %40, %33
br i1 %41, label %44, label %34
42: ; preds = %28, %30
%43 = tail call i32 @putchar(i8 signext 10)
br label %56
44: ; preds = %34
%45 = tail call i32 @putchar(i8 signext 10)
br i1 %3, label %46, label %56
46: ; preds = %44
%47 = zext i32 %2 to i64
br label %48
48: ; preds = %48, %46
%49 = phi i64 [ 0, %46 ], [ %54, %48 ]
%50 = getelementptr inbounds i8, i8* %0, i64 %49
%51 = load i8, i8* %50
%52 = tail call i32 @putchar(i8 signext %51)
%53 = tail call i32 (...) @sched_yield()
%54 = add nuw nsw i64 %49, 1
%55 = icmp eq i64 %54, %47
br i1 %55, label %58, label %48
56: ; preds = %42, %44
%57 = tail call i32 @putchar(i8 signext 10)
br label %70
58: ; preds = %48
%59 = tail call i32 @putchar(i8 signext 10)
br i1 %3, label %60, label %70
60: ; preds = %58
%61 = zext i32 %2 to i64
br label %62
62: ; preds = %62, %60
%63 = phi i64 [ 0, %60 ], [ %68, %62 ]
%64 = getelementptr inbounds i8, i8* %0, i64 %63
%65 = load i8, i8* %64
%66 = tail call i32 @putchar(i8 signext %65)
%67 = tail call i32 (...) @sched_yield()
%68 = add nuw nsw i64 %63, 1
%69 = icmp eq i64 %68, %61
br i1 %69, label %72, label %62
70: ; preds = %56, %58
%71 = tail call i32 @putchar(i8 signext 10)
br label %84
72: ; preds = %62
%73 = tail call i32 @putchar(i8 signext 10)
br i1 %3, label %74, label %84
74: ; preds = %72
%75 = zext i32 %2 to i64
br label %76
76: ; preds = %76, %74
%77 = phi i64 [ 0, %74 ], [ %82, %76 ]
%78 = getelementptr inbounds i8, i8* %0, i64 %77
%79 = load i8, i8* %78
%80 = tail call i32 @putchar(i8 signext %79)
%81 = tail call i32 (...) @sched_yield()
%82 = add nuw nsw i64 %77, 1
%83 = icmp eq i64 %82, %75
br i1 %83, label %86, label %76
84: ; preds = %70, %72
%85 = tail call i32 @putchar(i8 signext 10)
br label %98
86: ; preds = %76
%87 = tail call i32 @putchar(i8 signext 10)
br i1 %3, label %88, label %98
88: ; preds = %86
%89 = zext i32 %2 to i64
br label %90
90: ; preds = %90, %88
%91 = phi i64 [ 0, %88 ], [ %96, %90 ]
%92 = getelementptr inbounds i8, i8* %0, i64 %91
%93 = load i8, i8* %92
%94 = tail call i32 @putchar(i8 signext %93)
%95 = tail call i32 (...) @sched_yield()
%96 = add nuw nsw i64 %91, 1
%97 = icmp eq i64 %96, %89
br i1 %97, label %100, label %90
98: ; preds = %84, %86
%99 = tail call i32 @putchar(i8 signext 10)
br label %112
100: ; preds = %90
%101 = tail call i32 @putchar(i8 signext 10)
br i1 %3, label %102, label %112
102: ; preds = %100
%103 = zext i32 %2 to i64
br label %104
104: ; preds = %104, %102
%105 = phi i64 [ 0, %102 ], [ %110, %104 ]
%106 = getelementptr inbounds i8, i8* %0, i64 %105
%107 = load i8, i8* %106
%108 = tail call i32 @putchar(i8 signext %107)
%109 = tail call i32 (...) @sched_yield()
%110 = add nuw nsw i64 %105, 1
%111 = icmp eq i64 %110, %103
br i1 %111, label %114, label %104
112: ; preds = %98, %100
%113 = tail call i32 @putchar(i8 signext 10)
br label %126
114: ; preds = %104
%115 = tail call i32 @putchar(i8 signext 10)
br i1 %3, label %116, label %126
116: ; preds = %114
%117 = zext i32 %2 to i64
br label %118
118: ; preds = %118, %116
%119 = phi i64 [ 0, %116 ], [ %124, %118 ]
%120 = getelementptr inbounds i8, i8* %0, i64 %119
%121 = load i8, i8* %120
%122 = tail call i32 @putchar(i8 signext %121)
%123 = tail call i32 (...) @sched_yield()
%124 = add nuw nsw i64 %119, 1
%125 = icmp eq i64 %124, %117
br i1 %125, label %128, label %118
126: ; preds = %112, %114
%127 = tail call i32 @putchar(i8 signext 10)
br label %140
128: ; preds = %118
%129 = tail call i32 @putchar(i8 signext 10)
br i1 %3, label %130, label %140
130: ; preds = %128
%131 = zext i32 %2 to i64
br label %132
132: ; preds = %132, %130
%133 = phi i64 [ 0, %130 ], [ %138, %132 ]
%134 = getelementptr inbounds i8, i8* %0, i64 %133
%135 = load i8, i8* %134
%136 = tail call i32 @putchar(i8 signext %135)
%137 = tail call i32 (...) @sched_yield()
%138 = add nuw nsw i64 %133, 1
%139 = icmp eq i64 %138, %131
br i1 %139, label %140, label %132
140: ; preds = %132, %126, %128
%141 = tail call i32 @putchar(i8 signext 10)
ret i8* undef
}