#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*/ FILE;

/* Variables and functions */
int getc(int /*<<< orphan*/ *);
scalar_t__ isdigit(int);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int read_signed_integer(FILE *stream) {
  register int c = getc(stream);
  register int sign = 1;
  register int n;
  if (c == '-') {
    c = getc(stream);
    sign = -1;
  }
  n = 0;
  while (isdigit(c)) {
    n = 10 * n + (c - '0');
    c = getc(stream);
  }
  ungetc(c, stream);
  return n * sign;
}


x86 assembly (clang, -O0):
<read_signed_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x2d,-0xc(%rbp)
jne    116c <read_signed_integer+0x3c>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11a5 <read_signed_integer+0x75>
imul   $0xa,-0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0xc(%rbp)
jmp    1173 <read_signed_integer+0x43>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <ungetc@plt>
mov    -0x14(%rbp),%eax
imul   -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_signed_integer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <getc@plt>
cmp    $0x2d,%eax
jne    1156 <read_signed_integer+0x26>
mov    %r14,%rdi
call   1050 <getc@plt>
mov    %eax,%r15d
mov    $0xffffffff,%ebp
jmp    115e <read_signed_integer+0x2e>
mov    %eax,%r15d
mov    $0x1,%ebp
mov    %r15d,%edi
call   1030 <isdigit@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1191 <read_signed_integer+0x61>
nopl   (%rax)
lea    (%rbx,%rbx,4),%eax
lea    (%r15,%rax,2),%ebx
add    $0xffffffd0,%ebx
mov    %r14,%rdi
call   1050 <getc@plt>
mov    %eax,%r15d
mov    %eax,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <read_signed_integer+0x40>
imul   %ebp,%ebx
mov    %r15d,%edi
mov    %r14,%rsi
call   1040 <ungetc@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_signed_integer(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @getc(i32* %6)
store i32 %7, i32* %3
store i32 1, i32* %4
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 45
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32*, i32** %2
%12 = call i32 @getc(i32* %11)
store i32 %12, i32* %3
store i32 -1, i32* %4
br label %13
13: ; preds = %10, %1
store i32 0, i32* %5
br label %14
14: ; preds = %18, %13
%15 = load i32, i32* %3
%16 = call i64 @isdigit(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32, i32* %5
%20 = mul nsw i32 10, %19
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 48
%23 = add nsw i32 %20, %22
store i32 %23, i32* %5
%24 = load i32*, i32** %2
%25 = call i32 @getc(i32* %24)
store i32 %25, i32* %3
br label %14
26: ; preds = %14
%27 = load i32, i32* %3
%28 = load i32*, i32** %2
%29 = call i32 @ungetc(i32 %27, i32* %28)
%30 = load i32, i32* %5
%31 = load i32, i32* %4
%32 = mul nsw i32 %30, %31
ret i32 %32
}

LLVM IR (-O2):
define i32 @read_signed_integer(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = icmp eq i32 %2, 45
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @getc(i32* %0)
br label %6
6: ; preds = %4, %1
%7 = phi i32 [ %5, %4 ], [ %2, %1 ]
%8 = phi i32 [ -1, %4 ], [ 1, %1 ]
%9 = tail call i64 @isdigit(i32 %7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %6, %11
%12 = phi i32 [ %16, %11 ], [ 0, %6 ]
%13 = phi i32 [ %17, %11 ], [ %7, %6 ]
%14 = mul nsw i32 %12, 10
%15 = add nsw i32 %13, -48
%16 = add nsw i32 %15, %14
%17 = tail call i32 @getc(i32* %0)
%18 = tail call i64 @isdigit(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %11
20: ; preds = %11, %6
%21 = phi i32 [ %7, %6 ], [ %17, %11 ]
%22 = phi i32 [ 0, %6 ], [ %16, %11 ]
%23 = tail call i32 @ungetc(i32 %21, i32* %0)
%24 = mul nsw i32 %22, %8
ret i32 %24
}