int main(int argc, char **argv) {
  int a = atoi(argv[1]);
  int b = atoi(argv[2]);
  int c;
  printf("%d * %d = ", a, b);
  if (__builtin_choose_expr(
          __builtin_types_compatible_p(typeof(*(&c)), signed char),
          overflow_mul_c((signed char *)&c, a, b),
          __builtin_choose_expr(
              __builtin_types_compatible_p(typeof(*(&c)), short),
              overflow_mul_h((short *)&c, a, b),
              __builtin_choose_expr(
                  __builtin_types_compatible_p(typeof(*(&c)), int),
                  overflow_mul_i((int *)&c, a, b),
                  __builtin_choose_expr(
                      __builtin_types_compatible_p(typeof(*(&c)), long),
                      overflow_mul_l((long *)&c, a, b),
                      __builtin_choose_expr(
                          __builtin_types_compatible_p(typeof(*(&c)),
                                                       long long),
                          overflow_mul_q((long long *)&c, a, b),
                          __builtin_choose_expr(
                              __builtin_types_compatible_p(typeof(*(&c)),
                                                           unsigned char),
                              overflow_mul_b((unsigned char *)&c, a, b),
                              __builtin_choose_expr(
                                  __builtin_types_compatible_p(typeof(*(&c)),
                                                               unsigned short),
                                  overflow_mul_H((unsigned short *)&c, a, b),
                                  __builtin_choose_expr(
                                      __builtin_types_compatible_p(
                                          typeof(*(&c)), unsigned int),
                                      overflow_mul_I((unsigned int *)&c, a, b),
                                      __builtin_choose_expr(
                                          __builtin_types_compatible_p(
                                              typeof(*(&c)), unsigned long),
                                          overflow_mul_L((unsigned long *)&c, a,
                                                         b),
                                          __builtin_choose_expr(
                                              __builtin_types_compatible_p(
                                                  typeof(*(&c)),
                                                  unsigned long long),
                                              overflow_mul_Q(
                                                  (unsigned long long *)&c, a,
                                                  b),
                                              (void)0)))))))))))
    printf("overflow!\n");
  else
    printf("%d\n", c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x0,%al
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x0,%al
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    -0x1c(%rbp),%rdi
mov    $0x0,%al
call   1040 <overflow_mul_i@plt>
cmp    $0x0,%eax
je     11ab <main+0x7b>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bc <main+0x8c>
mov    -0x1c(%rbp),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %eax,%eax
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
xor    %eax,%eax
call   1060 <atoi@plt>
mov    %eax,%ebx
lea    0xe99(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <overflow_mul_i@plt>
test   %eax,%eax
je     1194 <main+0x54>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
jmp    11a6 <main+0x66>
mov    0x4(%rsp),%esi
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%d * %d = \00"
@.str.1 = [11 x i8] c"overflow!\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %11)
store i32 %12, i32* %6
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @overflow_mul_i to i32 (i32*, i32, i32, ...)*)(i32* %8, i32 %20, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %29
26: ; preds = %2
%27 = load i32, i32* %8
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %24
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [11 x i8] c"%d * %d = \00"
@.str.2 = [4 x i8] c"%d\0A\00"
@str = [10 x i8] c"overflow!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %8)
%10 = bitcast i32* %3 to i8*
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9)
%12 = call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @overflow_mul_i to i32 (i32*, i32, i32, ...)*)(i32* %3, i32 %6, i32 %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %19
16: ; preds = %2
%17 = load i32, i32* %3
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %14
ret i32 0
}