#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 */
struct pevent {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ pevent_register_comm(struct pevent *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, char **);
char *strtok_r(char *, char *, char **);
void parse_cmdlines(struct pevent *pevent, char *file,
                    int size __attribute__((unused))) {
  char *comm;
  char *line;
  char *next = NULL;
  int pid;
  line = strtok_r(file, "\n", &next);
  while (line) {
    sscanf(line, "%d %ms", &pid, &comm);
    pevent_register_comm(pevent, comm, pid);
    free(comm);
    line = strtok_r(NULL, "\n", &next);
  }
}


x86 assembly (clang, -O0):
<parse_cmdlines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9a(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cc <parse_cmdlines+0x8c>
mov    -0x28(%rbp),%rdi
lea    0xe79(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1050 <sscanf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1060 <pevent_register_comm@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe46(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
jmp    1173 <parse_cmdlines+0x33>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cmdlines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0xe9c(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11de <parse_cmdlines+0x9e>
lea    0xe85(%rip),%r14
lea    0x4(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xe72(%rip),%r13
lea    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1050 <sscanf@plt>
mov    0x10(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
call   1060 <pevent_register_comm@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
jne    11a0 <parse_cmdlines+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pevent = type { i32 }
@.str = [2 x i8] c"\0A\00"
@.str.1 = [7 x i8] c"%d %ms\00"
define void @parse_cmdlines(%struct.pevent* %0, i8* %1, i32 %2) {
%4 = alloca %struct.pevent*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store %struct.pevent* %0, %struct.pevent** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %9
%11 = load i8*, i8** %5
%12 = call i8* @strtok_r(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9)
store i8* %12, i8** %8
br label %13
13: ; preds = %16, %3
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i8*, i8** %8
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %10, i8** %7)
%19 = load %struct.pevent*, %struct.pevent** %4
%20 = load i8*, i8** %7
%21 = load i32, i32* %10
%22 = call i32 @pevent_register_comm(%struct.pevent* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %7
%24 = call i32 @free(i8* %23)
%25 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9)
store i8* %25, i8** %8
br label %13
26: ; preds = %13
ret void
}

LLVM IR (-O2):
%struct.pevent = type { i32 }
@.str = [2 x i8] c"\0A\00"
@.str.1 = [7 x i8] c"%d %ms\00"
define void @parse_cmdlines(%struct.pevent* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = bitcast i8** %4 to i8*
%8 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%9 = bitcast i32* %6 to i8*
%10 = call i8* @strtok_r(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%11 = icmp eq i8* %10, null
br i1 %11, label %22, label %12
12: ; preds = %3, %12
%13 = phi i8* [ %20, %12 ], [ %10, %3 ]
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8** %4)
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = call i32 @pevent_register_comm(%struct.pevent* %0, i8* %15, i32 %16)
%18 = load i8*, i8** %4
%19 = call i32 @free(i8* %18)
%20 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %12
22: ; preds = %12, %3
ret void
}