#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 INT_MIN;
scalar_t__ RAND_MAX;
int abs(int);
int atoi(char *);
int /*<<< orphan*/ fail(char *);
int /*<<< orphan*/ pr(char *);
int rand();
void test_math(void) {
  int i, j, k;
  int rns[100];
  pr("atoi");
  i = 12345;
  if (i != atoi("   12345"))
    fail("atoi-1");
  if (i != atoi("\t+12345"))
    fail("atoi-2");
  i = -i;
  if (i != atoi("-12345"))
    fail("atoi-3");
  if (i != atoi("  -12345"))
    fail("atoi-4");
  if (i != atoi("\t-12345"))
    fail("atoi-5");
  pr("abs");
  if (abs(0) != 0)
    fail("abs-1");
  if (abs(123) != 123)
    fail("abs-2");
  if (abs(-456) != 456)
    fail("abs-3");
  if (abs(INT_MIN) != INT_MIN)
    fail("abs-4");
  for (i = 0; i < 100; i++) {
    k = rand();
    for (j = 0; j < i; j++)
      if (rns[j] == k) {
        fail("rand-1");
        break;
      }
    rns[i] = k;
    if ((char *)k > (char *)RAND_MAX)
      fail("rand-2");
  }
}


x86 assembly (clang, -O0):
<test_math>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
lea    0xe9e(%rip),%rdi
call   1050 <pr@plt>
movl   $0x3039,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1a4(%rbp)
lea    0xe87(%rip),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x1a4(%rbp),%eax
cmp    %ecx,%eax
je     119f <test_math+0x4f>
lea    0xe74(%rip),%rdi
call   1040 <fail@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1a8(%rbp)
lea    0xe66(%rip),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x1a8(%rbp),%eax
cmp    %ecx,%eax
je     11d0 <test_math+0x80>
lea    0xe52(%rip),%rdi
call   1040 <fail@plt>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1ac(%rbp)
lea    0xe54(%rip),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x1ac(%rbp),%eax
cmp    %ecx,%eax
je     1209 <test_math+0xb9>
lea    0xe20(%rip),%rdi
call   1040 <fail@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
lea    0xe12(%rip),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x1b0(%rbp),%eax
cmp    %ecx,%eax
je     123a <test_math+0xea>
lea    0xdff(%rip),%rdi
call   1040 <fail@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1b4(%rbp)
lea    0xdf1(%rip),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x1b4(%rbp),%eax
cmp    %ecx,%eax
je     126b <test_math+0x11b>
lea    0xddd(%rip),%rdi
call   1040 <fail@plt>
lea    0xdd8(%rip),%rdi
call   1050 <pr@plt>
xor    %edi,%edi
call   1030 <abs@plt>
cmp    $0x0,%eax
je     1293 <test_math+0x143>
lea    0xdc0(%rip),%rdi
call   1040 <fail@plt>
mov    $0x7b,%edi
call   1030 <abs@plt>
cmp    $0x7b,%eax
je     12b2 <test_math+0x162>
lea    0xda7(%rip),%rdi
call   1040 <fail@plt>
mov    $0xfffffe38,%edi
call   1030 <abs@plt>
cmp    $0x1c8,%eax
je     12d3 <test_math+0x183>
lea    0xd8c(%rip),%rdi
call   1040 <fail@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   1030 <abs@plt>
mov    0x2cf8(%rip),%rcx
cmp    (%rcx),%eax
je     12fc <test_math+0x1ac>
lea    0xd69(%rip),%rdi
call   1040 <fail@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x64,-0x4(%rbp)
jge    13a6 <test_math+0x256>
mov    $0x0,%al
call   1070 <rand@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1362 <test_math+0x212>
movslq -0x8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0xc(%rbp),%eax
jne    134f <test_math+0x1ff>
lea    0xd21(%rip),%rdi
call   1040 <fail@plt>
jmp    1362 <test_math+0x212>
jmp    1354 <test_math+0x204>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    131e <test_math+0x1ce>
mov    -0xc(%rbp),%ecx
movslq -0x4(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
movslq -0xc(%rbp),%rax
mov    0x2c6d(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
jbe    1393 <test_math+0x243>
lea    0xcdf(%rip),%rdi
call   1040 <fail@plt>
jmp    1398 <test_math+0x248>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <test_math+0x1b3>
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_math>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x190,%rsp
lea    0xeba(%rip),%rdi
call   1040 <pr@plt>
lea    0xeb3(%rip),%rdi
call   1040 <pr@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
cmp    %eax,%ecx
je     1177 <test_math+0x47>
lea    0xe97(%rip),%rdi
call   1030 <fail@plt>
mov    0x2e6a(%rip),%r12
lea    0xe91(%rip),%r15
lea    0xe83(%rip),%r14
xor    %ebx,%ebx
jmp    119a <test_math+0x6a>
add    $0x1,%rbx
cmp    $0x64,%rbx
je     11de <test_math+0xae>
xor    %eax,%eax
call   1050 <rand@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     11c8 <test_math+0x98>
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
cmp    %ebp,(%rsp,%rax,4)
je     11c0 <test_math+0x90>
add    $0x1,%rax
cmp    %rax,%rbx
jne    11b0 <test_math+0x80>
jmp    11c8 <test_math+0x98>
mov    %r14,%rdi
call   1030 <fail@plt>
mov    %ebp,(%rsp,%rbx,4)
movslq %ebp,%rax
cmp    (%r12),%rax
jbe    1190 <test_math+0x60>
mov    %r15,%rdi
call   1030 <fail@plt>
jmp    1190 <test_math+0x60>
add    $0x190,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"atoi\00"
@.str.1 = [9 x i8] c" 12345\00"
@.str.2 = [7 x i8] c"atoi-1\00"
@.str.3 = [8 x i8] c"\09+12345\00"
@.str.4 = [7 x i8] c"atoi-2\00"
@.str.5 = [7 x i8] c"-12345\00"
@.str.6 = [7 x i8] c"atoi-3\00"
@.str.7 = [9 x i8] c" -12345\00"
@.str.8 = [7 x i8] c"atoi-4\00"
@.str.9 = [8 x i8] c"\09-12345\00"
@.str.10 = [7 x i8] c"atoi-5\00"
@.str.11 = [4 x i8] c"abs\00"
@.str.12 = [6 x i8] c"abs-1\00"
@.str.13 = [6 x i8] c"abs-2\00"
@.str.14 = [6 x i8] c"abs-3\00"
@INT_MIN = global i32 0
@.str.15 = [6 x i8] c"abs-4\00"
@.str.16 = [7 x i8] c"rand-1\00"
@RAND_MAX = global i64 0
@.str.17 = [7 x i8] c"rand-2\00"
define void @test_math() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i32]
%5 = call i32 @pr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 12345, i32* %1
%6 = load i32, i32* %1
%7 = call i32 @atoi(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = load i32, i32* %1
%13 = call i32 @atoi(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = load i32, i32* %1
%19 = sub nsw i32 0, %18
store i32 %19, i32* %1
%20 = load i32, i32* %1
%21 = call i32 @atoi(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %25
25: ; preds = %23, %17
%26 = load i32, i32* %1
%27 = call i32 @atoi(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
%32 = load i32, i32* %1
%33 = call i32 @atoi(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = call i32 @pr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%39 = call i32 @abs(i32 0)
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = call i32 @abs(i32 123)
%45 = icmp ne i32 %44, 123
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = call i32 @abs(i32 -456)
%50 = icmp ne i32 %49, 456
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 @fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
%54 = load i32, i32* @INT_MIN
%55 = call i32 @abs(i32 %54)
%56 = load i32, i32* @INT_MIN
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 @fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
store i32 0, i32* %1
br label %61
61: ; preds = %97, %60
%62 = load i32, i32* %1
%63 = icmp slt i32 %62, 100
br i1 %63, label %64, label %100
64: ; preds = %61
%65 = call i32 (...) @rand()
store i32 %65, i32* %3
store i32 0, i32* %2
br label %66
66: ; preds = %80, %64
%67 = load i32, i32* %2
%68 = load i32, i32* %1
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %83
70: ; preds = %66
%71 = load i32, i32* %2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = load i32, i32* %3
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %79
77: ; preds = %70
%78 = call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0))
br label %83
79: ; preds = %70
br label %80
80: ; preds = %79
%81 = load i32, i32* %2
%82 = add nsw i32 %81, 1
store i32 %82, i32* %2
br label %66
83: ; preds = %77, %66
%84 = load i32, i32* %3
%85 = load i32, i32* %1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %86
store i32 %84, i32* %87
%88 = load i32, i32* %3
%89 = sext i32 %88 to i64
%90 = inttoptr i64 %89 to i8*
%91 = load i64, i64* @RAND_MAX
%92 = inttoptr i64 %91 to i8*
%93 = icmp ugt i8* %90, %92
br i1 %93, label %94, label %96
94: ; preds = %83
%95 = call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
br label %96
96: ; preds = %94, %83
br label %97
97: ; preds = %96
%98 = load i32, i32* %1
%99 = add nsw i32 %98, 1
store i32 %99, i32* %1
br label %61
100: ; preds = %61
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"atoi\00"
@.str.11 = [4 x i8] c"abs\00"
@INT_MIN = global i32 0
@.str.15 = [6 x i8] c"abs-4\00"
@.str.16 = [7 x i8] c"rand-1\00"
@RAND_MAX = global i64 0
@.str.17 = [7 x i8] c"rand-2\00"
define void @test_math() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to i8*
%3 = tail call i32 @pr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @pr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%5 = load i32, i32* @INT_MIN
%6 = tail call i32 @llvm.abs.i32(i32 %5, i1 true)
%7 = icmp eq i32 %6, %5
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = tail call i32 @fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.15, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
br label %11
11: ; preds = %10, %34
%12 = phi i64 [ %35, %34 ], [ 0, %10 ]
%13 = tail call i32 (...) @rand()
%14 = icmp eq i64 %12, 0
br i1 %14, label %25, label %17
15: ; preds = %17
%16 = icmp eq i64 %22, %12
br i1 %16, label %25, label %17
17: ; preds = %11, %15
%18 = phi i64 [ %22, %15 ], [ 0, %11 ]
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, %13
%22 = add nuw nsw i64 %18, 1
br i1 %21, label %23, label %15
23: ; preds = %17
%24 = tail call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0))
br label %25
25: ; preds = %15, %11, %23
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %12
store i32 %13, i32* %26
%27 = sext i32 %13 to i64
%28 = inttoptr i64 %27 to i8*
%29 = load i64, i64* @RAND_MAX
%30 = inttoptr i64 %29 to i8*
%31 = icmp ugt i8* %28, %30
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = tail call i32 @fail(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0))
br label %34
34: ; preds = %25, %32
%35 = add nuw nsw i64 %12, 1
%36 = icmp eq i64 %35, 100
br i1 %36, label %37, label %11
37: ; preds = %34
ret void
}