#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*/ printf(char *, ...);
char *strsep(char **, char *);
int main(int argc, char **argv) {
  char a[] = "function bind\r\ndevid 1233\r\nphoneid 45312\r\n";
  char buf[8192];
  char *delim = "\r\n";
  char *p;
  int c = 0;
  printf("a %s\n", a);
  char *p1 = a;
  while ((p = strsep(&p1, delim)) != NULL) {
    c++;
    printf("get line %d:%s'\n", c, p);
  }
  printf("a %s\n", a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2060,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeac(%rip),%rsi
mov    $0x2b,%edx
call   1040 <memcpy@plt>
lea    0xec6(%rip),%rax
mov    %rax,-0x2048(%rbp)
movl   $0x0,-0x2054(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x2060(%rbp)
mov    -0x2048(%rbp),%rsi
lea    -0x2060(%rbp),%rdi
call   1050 <strsep@plt>
mov    %rax,-0x2050(%rbp)
cmp    $0x0,%rax
je     11e6 <main+0xb6>
mov    -0x2054(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2054(%rbp)
mov    -0x2054(%rbp),%esi
mov    -0x2050(%rbp),%rdx
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1193 <main+0x63>
lea    -0x40(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x2060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
movups 0xee9(%rip),%xmm0
movups %xmm0,0x2b(%rsp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xed8(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,0x8(%rsp)
lea    0xeba(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1040 <strsep@plt>
test   %rax,%rax
je     11c2 <main+0xa2>
mov    $0x1,%ebx
lea    0xea8(%rip),%r14
lea    0xe98(%rip),%r15
lea    0x8(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strsep@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    11a0 <main+0x80>
lea    0xe65(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.a = [43 x i8] c"function bind\0D\0Adevid 1233\0D\0Aphoneid 45312\0D\0A\00"
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [6 x i8] c"a %s\0A\00"
@.str.2 = [17 x i8] c"get line %d:%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [43 x i8]
%7 = alloca [8192 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [43 x i8]* %6 to i8*
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %8
store i32 0, i32* %10
%13 = getelementptr inbounds [43 x i8], [43 x i8]* %6, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [43 x i8], [43 x i8]* %6, i64 0, i64 0
store i8* %15, i8** %11
br label %16
16: ; preds = %20, %2
%17 = load i8*, i8** %8
%18 = call i8* @strsep(i8** %11, i8* %17)
store i8* %18, i8** %9
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i32, i32* %10
%22 = add nsw i32 %21, 1
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = load i8*, i8** %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %24)
br label %16
26: ; preds = %16
%27 = getelementptr inbounds [43 x i8], [43 x i8]* %6, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %27)
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [43 x i8] c"function bind\0D\0Adevid 1233\0D\0Aphoneid 45312\0D\0A\00"
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [6 x i8] c"a %s\0A\00"
@.str.2 = [17 x i8] c"get line %d:%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [43 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [43 x i8], [43 x i8]* %3, i64 0, i64 0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = bitcast i8** %4 to i8*
store i8* %5, i8** %4
%8 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %17, label %10
10: ; preds = %2, %10
%11 = phi i8* [ %15, %10 ], [ %8, %2 ]
%12 = phi i32 [ %13, %10 ], [ 0, %2 ]
%13 = add nuw nsw i32 %12, 1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %13, i8* %11)
%15 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %10
17: ; preds = %10, %2
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5)
ret i32 0
}