#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 strtol(char *, char **, int);
int getsyslogpid(char *syslogbanner, int length) {
  int i;
  syslogbanner[length - 2] = '\0';
  for (i = length; syslogbanner[i] != '['; i--)
    ;
  return strtol(&syslogbanner[i + 1], (char **)NULL, 10);
}


x86 assembly (clang, -O0):
<getsyslogpid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5b,%eax
je     115e <getsyslogpid+0x4e>
jmp    1150 <getsyslogpid+0x40>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <getsyslogpid+0x26>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getsyslogpid>:
movslq %esi,%rdx
movb   $0x0,-0x2(%rdi,%rdx,1)
lea    (%rdi,%rdx,1),%rcx
shl    $0x20,%rdx
movabs $0x200000000,%rax
add    %rdx,%rax
movabs $0xffffffff00000000,%rdx
ff ff ff
nopw   0x0(%rax,%rax,1)
add    %rdx,%rax
cmpb   $0x5b,(%rcx)
lea    -0x1(%rcx),%rcx
jne    1140 <getsyslogpid+0x30>
sar    $0x20,%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
jmp    1030 <strtol@plt>

LLVM IR (-O0):
define i32 @getsyslogpid(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = sub nsw i32 %7, 2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8 0, i8* %10
%11 = load i32, i32* %4
store i32 %11, i32* %5
br label %12
12: ; preds = %21, %2
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 91
br i1 %19, label %20, label %24
20: ; preds = %12
br label %21
21: ; preds = %20
%22 = load i32, i32* %5
%23 = add nsw i32 %22, -1
store i32 %23, i32* %5
br label %12
24: ; preds = %12
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = call i32 @strtol(i8* %29, i8** null, i32 10)
ret i32 %30
}

LLVM IR (-O2):
define i32 @getsyslogpid(i8* nocapture %0, i32 %1) {
%3 = add nsw i32 %1, -2
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
store i8 0, i8* %5
%6 = sext i32 %1 to i64
br label %7
7: ; preds = %7, %2
%8 = phi i64 [ %12, %7 ], [ %6, %2 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 91
%12 = add i64 %8, -1
br i1 %11, label %13, label %7
13: ; preds = %7
%14 = shl i64 %8, 32
%15 = add i64 %14, 4294967296
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = tail call i32 @strtol(i8* nocapture %17, i8** null, i32 10)
ret i32 %18
}