#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*/ free(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
char *strdup(char *);
char *strstr(char *, char *);
int main(int argc, char *argv[]) {
  char *jobidstr = NULL;
  int count = 0;
  char *logfile_format, *tmpstr;
  logfile_format = strdup("%s %d %r %t <jobid=1221> asdasd");
  if (logfile_format && strstr(logfile_format, "<jobid=") && !jobidstr) {
    tmpstr = strstr(logfile_format, "<jobid=");
    while (tmpstr && *tmpstr != '\0' && *tmpstr != '>')
      tmpstr++, count++;
    if (*tmpstr != '\0')
      (*tmpstr) = '\0';
    tmpstr = tmpstr - count;
    printf("Extracted job id string %s from string %s", tmpstr, logfile_format);
  }
  free(logfile_format);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe94(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1257 <main+0x117>
mov    -0x28(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     1257 <main+0x117>
cmpq   $0x0,-0x18(%rbp)
jne    1257 <main+0x117>
mov    -0x28(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x31(%rbp)
je     11ee <main+0xae>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     11ee <main+0xae>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3e,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11fe <main+0xbe>
jmp    1218 <main+0xd8>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b9 <main+0x79>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122f <main+0xef>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1199 <main+0x59>
lea    0xec4(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     1199 <main+0x59>
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movzbl (%rax,%rcx,1),%edx
test   %dl,%dl
je     1187 <main+0x47>
cmp    $0x3e,%dl
je     1183 <main+0x43>
add    $0x1,%rcx
jmp    1170 <main+0x30>
movb   $0x0,(%rax,%rcx,1)
lea    0xe9a(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"%s %d %r %t <jobid=1221> asdasd\00"
@.str.1 = [8 x i8] c"<jobid=\00"
@.str.2 = [42 x i8] c"Extracted job id string %s from string %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 0, i32* %7
%10 = call i8* @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %59
13: ; preds = %2
%14 = load i8*, i8** %8
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %59
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %59, label %20
20: ; preds = %17
%21 = load i8*, i8** %8
%22 = call i8* @strstr(i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %22, i8** %9
br label %23
23: ; preds = %38, %20
%24 = load i8*, i8** %9
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i8*, i8** %9
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i8*, i8** %9
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 62
br label %36
36: ; preds = %31, %26, %23
%37 = phi i1 [ false, %26 ], [ false, %23 ], [ %35, %31 ]
br i1 %37, label %38, label %43
38: ; preds = %36
%39 = load i8*, i8** %9
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %9
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %23
43: ; preds = %36
%44 = load i8*, i8** %9
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = load i8*, i8** %9
store i8 0, i8* %49
br label %50
50: ; preds = %48, %43
%51 = load i8*, i8** %9
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = sub i64 0, %53
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8* %55, i8** %9
%56 = load i8*, i8** %9
%57 = load i8*, i8** %8
%58 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %56, i8* %57)
br label %59
59: ; preds = %50, %17, %13, %2
%60 = load i8*, i8** %8
%61 = call i32 @free(i8* %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"%s %d %r %t <jobid=1221> asdasd\00"
@.str.1 = [8 x i8] c"<jobid=\00"
@.str.2 = [42 x i8] c"Extracted job id string %s from string %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(32) i8* @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = tail call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %21, label %8
8: ; preds = %5, %12
%9 = phi i32 [ %14, %12 ], [ 0, %5 ]
%10 = phi i8* [ %13, %12 ], [ %6, %5 ]
%11 = load i8, i8* %10
switch i8 %11, label %12 [
i8 0, label %16
i8 62, label %15
]
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = add nuw nsw i32 %9, 1
br label %8
15: ; preds = %8
store i8 0, i8* %10
br label %16
16: ; preds = %8, %15
%17 = zext i32 %9 to i64
%18 = sub nsw i64 0, %17
%19 = getelementptr inbounds i8, i8* %10, i64 %18
%20 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %3)
br label %21
21: ; preds = %16, %5, %2
%22 = tail call i32 @free(i8* %3)
ret i32 0
}