#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 atoi(char *);
int /*<<< orphan*/ free(char *);
char *lp_pr_identifier();
char *strchr(char *, char);
char *strdup(char *);
int strlen(char *);
char *strstr(char *, char *);
int getid(char *mbuf) {
  char *p1, *p2, *p3;
  int lpr;
  mbuf = strdup(mbuf);
  if (!mbuf)
    return 0;
  lpr = strlen(lp_pr_identifier());
  p1 = mbuf;
  while ((p1 = strstr(p1, "\nSubject:"))) {
    p1 += 9;
    p2 = strchr(p1, '\n');
    if (!p2)
      return 0;
    *p2++ = 0;
    p3 = p1;
    while ((p3 = strstr(p3, lp_pr_identifier()))) {
      if (atoi(p3 + lpr))
        return atoi(p3 + lpr);
      p3 += lpr;
    }
    p1 = p2;
  }
  free(mbuf);
  return 0;
}


x86 assembly (clang, -O0):
<getid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <getid+0x30>
movl   $0x0,-0x4(%rbp)
jmp    12b4 <getid+0x144>
mov    $0x0,%al
call   1040 <lp_pr_identifier@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12a4 <getid+0x134>
mov    -0x18(%rbp),%rax
add    $0x9,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120d <getid+0x9d>
movl   $0x0,-0x4(%rbp)
jmp    12b4 <getid+0x144>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <lp_pr_identifier@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1297 <getid+0x127>
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
call   1070 <atoi@plt>
cmp    $0x0,%eax
je     1281 <getid+0x111>
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    12b4 <getid+0x144>
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1227 <getid+0xb7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ba <getid+0x4a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   1080 <strdup@plt>
test   %rax,%rax
je     123d <getid+0xcd>
mov    %rax,%r12
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <lp_pr_identifier@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0xe59(%rip),%rsi
mov    %r12,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     1233 <getid+0xc3>
mov    %rax,%rbp
movslq %ebx,%rbx
lea    0xe3f(%rip),%r14
add    $0x9,%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     123d <getid+0xcd>
mov    %rax,%r13
add    $0x1,%r13
movb   $0x0,(%rax)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <lp_pr_identifier@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     1220 <getid+0xb0>
mov    %rax,%rbp
add    %rbx,%rbp
mov    %rbp,%rdi
call   1070 <atoi@plt>
test   %eax,%eax
je     11f0 <getid+0x80>
jmp    1242 <getid+0xd2>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r14,%rsi
call   1090 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11c1 <getid+0x51>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1245 <getid+0xd5>
xor    %r15d,%r15d
jmp    1245 <getid+0xd5>
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"\0ASubject:\00"
define i32 @getid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i8* @strdup(i8* %8)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 0, i32* %2
br label %61
13: ; preds = %1
%14 = call i8* (...) @lp_pr_identifier()
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %7
%16 = load i8*, i8** %3
store i8* %16, i8** %4
br label %17
17: ; preds = %56, %13
%18 = load i8*, i8** %4
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %58
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 9
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = call i8* @strchr(i8* %24, i8 signext 10)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %29, label %28
28: ; preds = %21
store i32 0, i32* %2
br label %61
29: ; preds = %21
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %5
store i8 0, i8* %30
%32 = load i8*, i8** %4
store i8* %32, i8** %6
br label %33
33: ; preds = %51, %29
%34 = load i8*, i8** %6
%35 = call i8* (...) @lp_pr_identifier()
%36 = call i8* @strstr(i8* %34, i8* %35)
store i8* %36, i8** %6
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %56
38: ; preds = %33
%39 = load i8*, i8** %6
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = call i32 @atoi(i8* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %38
%46 = load i8*, i8** %6
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = call i32 @atoi(i8* %49)
store i32 %50, i32* %2
br label %61
51: ; preds = %38
%52 = load i32, i32* %7
%53 = load i8*, i8** %6
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8, i8* %53, i64 %54
store i8* %55, i8** %6
br label %33
56: ; preds = %33
%57 = load i8*, i8** %5
store i8* %57, i8** %4
br label %17
58: ; preds = %17
%59 = load i8*, i8** %3
%60 = call i32 @free(i8* %59)
store i32 0, i32* %2
br label %61
61: ; preds = %58, %45, %28, %12
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
@.str = [10 x i8] c"\0ASubject:\00"
define i32 @getid(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %32, label %4
4: ; preds = %1
%5 = tail call i8* (...) @lp_pr_identifier()
%6 = tail call i32 @strlen(i8* %5)
%7 = tail call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %30, label %9
9: ; preds = %4
%10 = sext i32 %6 to i64
br label %14
11: ; preds = %21
%12 = tail call i8* @strstr(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %30, label %14
14: ; preds = %9, %11
%15 = phi i8* [ %7, %9 ], [ %12, %11 ]
%16 = getelementptr inbounds i8, i8* %15, i64 9
%17 = tail call i8* @strchr(i8* %16, i8 signext 10)
%18 = icmp eq i8* %17, null
br i1 %18, label %32, label %19
19: ; preds = %14
%20 = getelementptr inbounds i8, i8* %17, i64 1
store i8 0, i8* %17
br label %21
21: ; preds = %26, %19
%22 = phi i8* [ %16, %19 ], [ %27, %26 ]
%23 = tail call i8* (...) @lp_pr_identifier()
%24 = tail call i8* @strstr(i8* dereferenceable(1) %22, i8* dereferenceable(1) %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %11, label %26
26: ; preds = %21
%27 = getelementptr inbounds i8, i8* %24, i64 %10
%28 = tail call i32 @atoi(i8* %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %21, label %32
30: ; preds = %11, %4
%31 = tail call i32 @free(i8* %2)
br label %32
32: ; preds = %14, %26, %1, %30
%33 = phi i32 [ 0, %30 ], [ 0, %1 ], [ %28, %26 ], [ 0, %14 ]
ret i32 %33
}