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

/* Variables and functions */
int INT_MAX;
int INT_MIN;
int /*<<< orphan*/ printf(char *, int, int);
scalar_t__ test(int, char *, int, int, int, char *);
int main(int argc, char *argv[]) {
  char buf[12];
  int rv = 0;
  int n_tests = 0;
  rv += test(1, buf, sizeof(buf), 0, 0, "0");
  n_tests++;
  rv += test(2, buf, sizeof(buf), -12345, 0, "-12345");
  n_tests++;
  rv += test(3, buf, sizeof(buf), 12345, 0, "12345");
  n_tests++;
  rv += test(4, buf, sizeof(buf), INT_MIN, 0, "-2147483648");
  n_tests++;
  rv += test(5, buf, sizeof(buf), INT_MAX, 0, "2147483647");
  n_tests++;
  rv += test(6, buf, 5, INT_MAX, -1, "2147");
  n_tests++;
  rv += test(7, buf, 5, INT_MIN, -1, "-214");
  n_tests++;
  printf("%d out of %d tests passed\n", n_tests - rv, n_tests);
  return rv;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x1c(%rbp),%rsi
mov    $0x1,%edi
mov    $0xc,%edx
xor    %r8d,%r8d
lea    0xea4(%rip),%r9
mov    %r8d,%ecx
call   1040 <test@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x1c(%rbp),%rsi
mov    $0x2,%edi
mov    $0xc,%edx
mov    $0xffffcfc7,%ecx
xor    %r8d,%r8d
lea    0xe6b(%rip),%r9
call   1040 <test@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x1c(%rbp),%rsi
mov    $0x3,%edi
mov    $0xc,%edx
mov    $0x3039,%ecx
xor    %r8d,%r8d
lea    0xe34(%rip),%r9
call   1040 <test@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x1c(%rbp),%rsi
mov    0x2deb(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edi
mov    $0xc,%edx
xor    %r8d,%r8d
lea    0xdfe(%rip),%r9
call   1040 <test@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x1c(%rbp),%rsi
mov    0x2db7(%rip),%rax
mov    (%rax),%ecx
mov    $0x5,%edi
mov    $0xc,%edx
xor    %r8d,%r8d
lea    0xdce(%rip),%r9
call   1040 <test@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x1c(%rbp),%rsi
mov    0x2d7b(%rip),%rax
mov    (%rax),%ecx
mov    $0x6,%edi
mov    $0x5,%edx
mov    $0xffffffff,%r8d
lea    0xd9a(%rip),%r9
call   1040 <test@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x1c(%rbp),%rsi
mov    0x2d34(%rip),%rax
mov    (%rax),%ecx
mov    $0x7,%edi
mov    $0x5,%edx
mov    $0xffffffff,%r8d
lea    0xd60(%rip),%r9
call   1040 <test@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
sub    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd3a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%r9
lea    0xc(%rsp),%r14
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0xc,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <test@plt>
mov    %rax,%r15
lea    0xea7(%rip),%r9
mov    $0x2,%edi
mov    %r14,%rsi
mov    $0xc,%edx
mov    $0xffffcfc7,%ecx
xor    %r8d,%r8d
call   1040 <test@plt>
mov    %rax,%rbx
add    %r15d,%ebx
lea    0xe81(%rip),%r9
mov    $0x3,%edi
mov    %r14,%rsi
mov    $0xc,%edx
mov    $0x3039,%ecx
xor    %r8d,%r8d
call   1040 <test@plt>
mov    %rax,%r15
add    %ebx,%r15d
mov    0x2e37(%rip),%r13
mov    0x0(%r13),%ecx
lea    0xe55(%rip),%r9
mov    $0x4,%edi
mov    %r14,%rsi
mov    $0xc,%edx
xor    %r8d,%r8d
call   1040 <test@plt>
mov    %rax,%rbx
add    %r15d,%ebx
mov    0x2e12(%rip),%rbp
mov    0x0(%rbp),%ecx
lea    0xe35(%rip),%r9
mov    $0x5,%edi
mov    %r14,%rsi
mov    $0xc,%edx
xor    %r8d,%r8d
call   1040 <test@plt>
mov    %rax,%r15
add    %ebx,%r15d
mov    0x0(%rbp),%ecx
lea    0xe1b(%rip),%r9
mov    $0x6,%edi
mov    %r14,%rsi
mov    $0x5,%edx
mov    $0xffffffff,%r8d
call   1040 <test@plt>
mov    %rax,%r12
add    %r15d,%r12d
mov    0x0(%r13),%ecx
lea    0xdf7(%rip),%r9
mov    $0x7,%ebp
mov    $0x7,%edi
mov    %r14,%rsi
mov    $0x5,%edx
mov    $0xffffffff,%r8d
call   1040 <test@plt>
mov    %rax,%rbx
add    %r12d,%ebx
sub    %ebx,%ebp
lea    0xdd0(%rip),%rdi
mov    %ebp,%esi
mov    $0x7,%edx
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [7 x i8] c"-12345\00"
@.str.2 = [6 x i8] c"12345\00"
@INT_MIN = global i32 0
@.str.3 = [12 x i8] c"-2147483648\00"
@INT_MAX = global i32 0
@.str.4 = [11 x i8] c"2147483647\00"
@.str.5 = [5 x i8] c"2147\00"
@.str.6 = [5 x i8] c"-214\00"
@.str.7 = [27 x i8] c"%d out of %d tests passed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [12 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%10 = call i64 @test(i32 1, i8* %9, i32 12, i32 0, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = add nsw i64 %12, %10
%14 = trunc i64 %13 to i32
store i32 %14, i32* %7
%15 = load i32, i32* %8
%16 = add nsw i32 %15, 1
store i32 %16, i32* %8
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%18 = call i64 @test(i32 2, i8* %17, i32 12, i32 -12345, i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = add nsw i64 %20, %18
%22 = trunc i64 %21 to i32
store i32 %22, i32* %7
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
store i32 %24, i32* %8
%25 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%26 = call i64 @test(i32 3, i8* %25, i32 12, i32 12345, i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %7
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
%33 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%34 = load i32, i32* @INT_MIN
%35 = call i64 @test(i32 4, i8* %33, i32 12, i32 %34, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = add nsw i64 %37, %35
%39 = trunc i64 %38 to i32
store i32 %39, i32* %7
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
%42 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%43 = load i32, i32* @INT_MAX
%44 = call i64 @test(i32 5, i8* %42, i32 12, i32 %43, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = add nsw i64 %46, %44
%48 = trunc i64 %47 to i32
store i32 %48, i32* %7
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
%51 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%52 = load i32, i32* @INT_MAX
%53 = call i64 @test(i32 6, i8* %51, i32 5, i32 %52, i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = add nsw i64 %55, %53
%57 = trunc i64 %56 to i32
store i32 %57, i32* %7
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
%60 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%61 = load i32, i32* @INT_MIN
%62 = call i64 @test(i32 7, i8* %60, i32 5, i32 %61, i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = add nsw i64 %64, %62
%66 = trunc i64 %65 to i32
store i32 %66, i32* %7
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
%69 = load i32, i32* %8
%70 = load i32, i32* %7
%71 = sub nsw i32 %69, %70
%72 = load i32, i32* %8
%73 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %71, i32 %72)
%74 = load i32, i32* %7
ret i32 %74
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [7 x i8] c"-12345\00"
@.str.2 = [6 x i8] c"12345\00"
@INT_MIN = global i32 0
@.str.3 = [12 x i8] c"-2147483648\00"
@INT_MAX = global i32 0
@.str.4 = [11 x i8] c"2147483647\00"
@.str.5 = [5 x i8] c"2147\00"
@.str.6 = [5 x i8] c"-214\00"
@.str.7 = [27 x i8] c"%d out of %d tests passed\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [12 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%5 = call i64 @test(i32 1, i8* %4, i32 12, i32 0, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @test(i32 2, i8* %4, i32 12, i32 -12345, i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = add i64 %6, %5
%8 = call i64 @test(i32 3, i8* %4, i32 12, i32 12345, i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%9 = add i64 %7, %8
%10 = load i32, i32* @INT_MIN
%11 = call i64 @test(i32 4, i8* %4, i32 12, i32 %10, i32 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%12 = add i64 %9, %11
%13 = load i32, i32* @INT_MAX
%14 = call i64 @test(i32 5, i8* %4, i32 12, i32 %13, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%15 = add i64 %12, %14
%16 = load i32, i32* @INT_MAX
%17 = call i64 @test(i32 6, i8* %4, i32 5, i32 %16, i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%18 = add i64 %15, %17
%19 = load i32, i32* @INT_MIN
%20 = call i64 @test(i32 7, i8* %4, i32 5, i32 %19, i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%21 = add i64 %18, %20
%22 = trunc i64 %21 to i32
%23 = sub nsw i32 7, %22
%24 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %23, i32 7)
ret i32 %22
}