#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int BUFSIZ;
int sigar_file2str(char *, char *, int);
int get_proc_signal_offset(void) {
  char buffer[BUFSIZ], *ptr = buffer;
  int fields = 0;
  int status = sigar_file2str("/proc/"
                              "self/stat",
                              buffer, sizeof(buffer));
  if (status != 0) {
    return 1;
  }
  while (*ptr) {
    if (*ptr++ == ' ') {
      fields++;
    }
  }
  return (fields - 38) + 1;
}


x86 assembly (clang, -O0):
<get_proc_signal_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2ec1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,%rsp
mov    %rax,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    %eax,%edx
lea    0xeac(%rip),%rdi
call   1030 <sigar_file2str@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1179 <get_proc_signal_offset+0x69>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11c7 <get_proc_signal_offset+0xb7>
jmp    117e <get_proc_signal_offset+0x6e>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b4 <get_proc_signal_offset+0xa4>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11af <get_proc_signal_offset+0x9f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117e <get_proc_signal_offset+0x6e>
mov    -0x24(%rbp),%eax
sub    $0x26,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_proc_signal_offset>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2ec3(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xec6(%rip),%rdi
mov    %rbx,%rsi
call   1030 <sigar_file2str@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    117f <get_proc_signal_offset+0x6f>
mov    (%rbx),%cl
test   %cl,%cl
je     117a <get_proc_signal_offset+0x6a>
add    $0x1,%rbx
xor    %eax,%eax
nopl   0x0(%rax)
xor    %edx,%edx
cmp    $0x20,%cl
sete   %dl
add    %edx,%eax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1160 <get_proc_signal_offset+0x50>
add    $0xffffffdb,%eax
jmp    117f <get_proc_signal_offset+0x6f>
mov    $0xffffffdb,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [16 x i8] c"/proc/self/stat\00"
define i32 @get_proc_signal_offset() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = load i32, i32* @BUFSIZ
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %2
%11 = alloca i8, i64 %9
store i64 %9, i64* %3
store i8* %11, i8** %4
store i32 0, i32* %5
%12 = trunc i64 %9 to i32
%13 = call i32 @sigar_file2str(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %0
store i32 1, i32* %1
store i32 1, i32* %7
br label %36
17: ; preds = %0
br label %18
18: ; preds = %31, %17
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
%25 = load i8, i8* %23
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 32
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %31
31: ; preds = %28, %22
br label %18
32: ; preds = %18
%33 = load i32, i32* %5
%34 = sub nsw i32 %33, 38
%35 = add nsw i32 %34, 1
store i32 %35, i32* %1
store i32 1, i32* %7
br label %36
36: ; preds = %32, %16
%37 = load i8*, i8** %2
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [16 x i8] c"/proc/self/stat\00"
define i32 @get_proc_signal_offset() {
%1 = load i32, i32* @BUFSIZ
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = call i32 @sigar_file2str(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %0
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %6, %9
%10 = phi i8 [ %17, %9 ], [ %7, %6 ]
%11 = phi i32 [ %16, %9 ], [ 0, %6 ]
%12 = phi i8* [ %13, %9 ], [ %3, %6 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = icmp eq i8 %10, 32
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %11, %15
%17 = load i8, i8* %13
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %9
19: ; preds = %9
%20 = add nsw i32 %16, -37
br label %21
21: ; preds = %6, %19, %0
%22 = phi i32 [ 1, %0 ], [ -37, %6 ], [ %20, %19 ]
ret i32 %22
}