#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*/ fixnum_neg(char, char *, int *);
int /*<<< orphan*/ foo(int, int, int);
int test_neg(void) {
  signed char x, y;
  int v, err;
  err = 0;
  x = -128;
  for (;;) {
    fixnum_neg(x, &y, &v);
    foo((int)x, (int)y, v);
    if ((v && x != -128) || (!v && x == -128))
      ++err;
    if (x == 127)
      break;
    ++x;
  }
  return err;
}


x86 assembly (clang, -O0):
<test_neg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
movb   $0x80,-0x1(%rbp)
lea    -0x2(%rbp),%rsi
lea    -0x8(%rbp),%rdx
movsbl -0x1(%rbp),%edi
call   1030 <fixnum_neg@plt>
movsbl -0x1(%rbp),%edi
movsbl -0x2(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1040 <foo@plt>
cmpl   $0x0,-0x8(%rbp)
je     116b <test_neg+0x4b>
movsbl -0x1(%rbp),%eax
cmp    $0xffffff80,%eax
jne    1182 <test_neg+0x62>
cmpl   $0x0,-0x8(%rbp)
jne    118b <test_neg+0x6b>
movsbl -0x1(%rbp),%eax
cmp    $0xffffff80,%eax
jne    118b <test_neg+0x6b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x7f,%eax
jne    119d <test_neg+0x7d>
jmp    11aa <test_neg+0x8a>
mov    -0x1(%rbp),%al
add    $0x1,%al
mov    %al,-0x1(%rbp)
jmp    1133 <test_neg+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_neg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
mov    $0xffffff80,%ebp
lea    0x3(%rsp),%r14
lea    0x4(%rsp),%r15
jmp    114e <test_neg+0x2e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
add    $0x1,%ebp
cmp    $0x80,%ebp
je     1185 <test_neg+0x65>
movsbl %bpl,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <fixnum_neg@plt>
movsbl 0x3(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %ebp,%edi
call   1040 <foo@plt>
mov    0x4(%rsp),%eax
cmp    $0xffffff80,%ebp
je     117a <test_neg+0x5a>
test   %eax,%eax
jne    1140 <test_neg+0x20>
cmp    $0xffffff80,%ebp
jne    1143 <test_neg+0x23>
test   %eax,%eax
je     1140 <test_neg+0x20>
jmp    1143 <test_neg+0x23>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test_neg() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %4
store i8 -128, i8* %1
br label %5
5: ; preds = %35, %0
%6 = load i8, i8* %1
%7 = call i32 @fixnum_neg(i8 signext %6, i8* %2, i32* %3)
%8 = load i8, i8* %1
%9 = sext i8 %8 to i32
%10 = load i8, i8* %2
%11 = sext i8 %10 to i32
%12 = load i32, i32* %3
%13 = call i32 @foo(i32 %9, i32 %11, i32 %12)
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %5
%17 = load i8, i8* %1
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, -128
br i1 %19, label %27, label %20
20: ; preds = %16, %5
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %20
%24 = load i8, i8* %1
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, -128
br i1 %26, label %27, label %30
27: ; preds = %23, %16
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %23, %20
%31 = load i8, i8* %1
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 127
br i1 %33, label %34, label %35
34: ; preds = %30
br label %38
35: ; preds = %30
%36 = load i8, i8* %1
%37 = add i8 %36, 1
store i8 %37, i8* %1
br label %5
38: ; preds = %34
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
define i32 @test_neg() {
%1 = alloca i8
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %23, %0
%5 = phi i32 [ %26, %23 ], [ -128, %0 ]
%6 = phi i32 [ %24, %23 ], [ 0, %0 ]
%7 = trunc i32 %5 to i8
%8 = call i32 @fixnum_neg(i8 signext %7, i8* %1, i32* %2)
%9 = load i8, i8* %1
%10 = sext i8 %9 to i32
%11 = load i32, i32* %2
%12 = call i32 @foo(i32 %5, i32 %10, i32 %11)
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
%15 = icmp ne i32 %5, -128
%16 = and i1 %15, %14
br i1 %16, label %21, label %17
17: ; preds = %4
%18 = icmp eq i32 %13, 0
%19 = icmp eq i32 %5, -128
%20 = and i1 %19, %18
br i1 %20, label %21, label %23
21: ; preds = %17, %4
%22 = add nsw i32 %6, 1
br label %23
23: ; preds = %21, %17
%24 = phi i32 [ %22, %21 ], [ %6, %17 ]
%25 = icmp eq i32 %5, 127
%26 = add nsw i32 %5, 1
br i1 %25, label %27, label %4
27: ; preds = %23
ret i32 %24
}