#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 */
struct num {
  int dummy;
};

/* Variables and functions */
char *get_nick(char const *);
int irc_notice(int, char const *, char *, ...);
int /*<<< orphan*/ num_free(struct num *);
int /*<<< orphan*/ num_string(struct num *);
struct num *xcalc(char *);
int on_user_calc(int fd, const char *from, const char *to, char *msg) {
  const char *nick = get_nick(from);
  int ret;
  struct num *num;
  if (!msg)
    return irc_notice(fd, to, "calc error");
  num = xcalc(msg);
  if (!num)
    return irc_notice(fd, to, "%s's result is an error!", nick);
  ret = irc_notice(fd, to, "%s's result is %s", nick, num_string(num));
  num_free(num);
  return ret;
}


x86 assembly (clang, -O0):
<on_user_calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <get_nick@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119c <on_user_calc+0x4c>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    0xe73(%rip),%rdx
mov    $0x0,%al
call   1050 <irc_notice@plt>
mov    %eax,-0x4(%rbp)
jmp    1222 <on_user_calc+0xd2>
mov    -0x20(%rbp),%rdi
call   1040 <xcalc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d5 <on_user_calc+0x85>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xe45(%rip),%rdx
mov    $0x0,%al
call   1050 <irc_notice@plt>
mov    %eax,-0x4(%rbp)
jmp    1222 <on_user_calc+0xd2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <num_string@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rcx
mov    %eax,%r8d
lea    0xe1b(%rip),%rdx
mov    $0x0,%al
call   1050 <irc_notice@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <num_free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<on_user_calc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %edi,%ebp
mov    %rsi,%rdi
call   1070 <get_nick@plt>
test   %rbx,%rbx
je     11b7 <on_user_calc+0x67>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <xcalc@plt>
test   %rax,%rax
je     11d4 <on_user_calc+0x84>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <num_string@plt>
lea    0xe96(%rip),%rdx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <irc_notice@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <num_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe42(%rip),%rdx
mov    %ebp,%edi
mov    %r15,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <irc_notice@plt>
lea    0xe30(%rip),%rdx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rcx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <irc_notice@plt>

LLVM IR (-O0):
%struct.num = type { i32 }
@.str = [11 x i8] c"calc error\00"
@.str.1 = [25 x i8] c"%s's result is an error!\00"
@.str.2 = [18 x i8] c"%s's result is %s\00"
define i32 @on_user_calc(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.num*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%13 = load i8*, i8** %7
%14 = call i8* @get_nick(i8* %13)
store i8* %14, i8** %10
%15 = load i8*, i8** %9
%16 = icmp ne i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %4
%18 = load i32, i32* %6
%19 = load i8*, i8** %8
%20 = call i32 (i32, i8*, i8*, ...) @irc_notice(i32 %18, i8* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %5
br label %41
21: ; preds = %4
%22 = load i8*, i8** %9
%23 = call %struct.num* @xcalc(i8* %22)
store %struct.num* %23, %struct.num** %12
%24 = load %struct.num*, %struct.num** %12
%25 = icmp ne %struct.num* %24, null
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = load i32, i32* %6
%28 = load i8*, i8** %8
%29 = load i8*, i8** %10
%30 = call i32 (i32, i8*, i8*, ...) @irc_notice(i32 %27, i8* %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 %30, i32* %5
br label %41
31: ; preds = %21
%32 = load i32, i32* %6
%33 = load i8*, i8** %8
%34 = load i8*, i8** %10
%35 = load %struct.num*, %struct.num** %12
%36 = call i32 @num_string(%struct.num* %35)
%37 = call i32 (i32, i8*, i8*, ...) @irc_notice(i32 %32, i8* %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %34, i32 %36)
store i32 %37, i32* %11
%38 = load %struct.num*, %struct.num** %12
%39 = call i32 @num_free(%struct.num* %38)
%40 = load i32, i32* %11
store i32 %40, i32* %5
br label %41
41: ; preds = %31, %26, %17
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
%struct.num = type { i32 }
@.str = [11 x i8] c"calc error\00"
@.str.1 = [25 x i8] c"%s's result is an error!\00"
@.str.2 = [18 x i8] c"%s's result is %s\00"
define i32 @on_user_calc(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i8* @get_nick(i8* %1)
%6 = icmp eq i8* %3, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 (i32, i8*, i8*, ...) @irc_notice(i32 %0, i8* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %18
9: ; preds = %4
%10 = tail call %struct.num* @xcalc(i8* %3)
%11 = icmp eq %struct.num* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (i32, i8*, i8*, ...) @irc_notice(i32 %0, i8* %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %18
14: ; preds = %9
%15 = tail call i32 @num_string(%struct.num* %10)
%16 = tail call i32 (i32, i8*, i8*, ...) @irc_notice(i32 %0, i8* %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 %15)
%17 = tail call i32 @num_free(%struct.num* %10)
br label %18
18: ; preds = %14, %12, %7
%19 = phi i32 [ %16, %14 ], [ %13, %12 ], [ %8, %7 ]
ret i32 %19
}