#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*/ printf(char *, int);
int tadd_ok(int x, int y) {
  int sum = x + y;
  printf("unsigned sum is %u\n", sum);
  printf("signed sum is %d\n", sum);
  for (int i = 3; i < 5; i++)
    sum += 1;
  if (x > 0 && y > 0 && sum < 0)
    return 0;
  else if (x < 0 && y < 0 && sum > 0)
    return 0;
  else
    return 1;
}


x86 assembly (clang, -O0):
<tadd_ok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xecf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xed4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x3,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    116d <tadd_ok+0x5d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <tadd_ok+0x3c>
cmpl   $0x0,-0x8(%rbp)
jle    1197 <tadd_ok+0x87>
cmpl   $0x0,-0xc(%rbp)
jle    1197 <tadd_ok+0x87>
cmpl   $0x0,-0x10(%rbp)
jge    1197 <tadd_ok+0x87>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <tadd_ok+0xb8>
cmpl   $0x0,-0x8(%rbp)
jge    11c1 <tadd_ok+0xb1>
cmpl   $0x0,-0xc(%rbp)
jge    11c1 <tadd_ok+0xb1>
cmpl   $0x0,-0x10(%rbp)
jle    11c1 <tadd_ok+0xb1>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <tadd_ok+0xb8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tadd_ok>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebx
lea    (%r14,%rbx,1),%ebp
lea    0xedc(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
lea    (%r14,%rbx,1),%ecx
add    $0x1,%ecx
test   %ebx,%ebx
jle    1150 <tadd_ok+0x40>
test   %r14d,%r14d
jle    1150 <tadd_ok+0x40>
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jl     1160 <tadd_ok+0x50>
test   %ebx,%r14d
setns  %al
test   %ecx,%ecx
sets   %cl
or     %al,%cl
movzbl %cl,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"unsigned sum is %u\0A\00"
@.str.1 = [18 x i8] c"signed sum is %d\0A\00"
define i32 @tadd_ok(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = add nsw i32 %8, %9
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %6
%14 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 3, i32* %7
br label %15
15: ; preds = %21, %2
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 5
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %21
21: ; preds = %18
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %15
24: ; preds = %15
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* %5
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 0, i32* %3
br label %45
34: ; preds = %30, %27, %24
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = load i32, i32* %5
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load i32, i32* %6
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 0, i32* %3
br label %45
44: ; preds = %40, %37, %34
store i32 1, i32* %3
br label %45
45: ; preds = %44, %43, %33
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [20 x i8] c"unsigned sum is %u\0A\00"
@.str.1 = [18 x i8] c"signed sum is %d\0A\00"
define i32 @tadd_ok(i32 %0, i32 %1) {
%3 = add i32 %1, %0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%6 = add i32 %3, 1
%7 = icmp sgt i32 %0, 0
%8 = icmp sgt i32 %1, 0
%9 = and i1 %7, %8
%10 = icmp slt i32 %6, -1
%11 = and i1 %9, %10
br i1 %11, label %18, label %12
12: ; preds = %2
%13 = and i32 %1, %0
%14 = icmp sgt i32 %13, -1
%15 = icmp slt i32 %6, 0
%16 = or i1 %14, %15
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %12, %2
%19 = phi i32 [ 0, %2 ], [ %17, %12 ]
ret i32 %19
}