#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ printf(char *, char const *, double);
double sqrt(long);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int /*<<< orphan*/);
int squareroot(const char *argument) {
  char *end = NULL;
  long number;
  if (!argument || *argument == '\0') {
    fprintf(stderr, "error: invalid argument, \"%s\".\n",
            argument ? argument : "(null)");
    return -1;
  }
  number = strtol(argument, &end, 0);
  if (end && *end != '\0') {
    fprintf(stderr, "warning: trailing garbage \"%s\".\n", end);
  }
  printf("Square root of %s is %f\n", argument, sqrt(number));
  return 0;
}


x86 assembly (clang, -O0):
<squareroot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116f <squareroot+0x2f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c2 <squareroot+0x82>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1193 <squareroot+0x53>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11a3 <squareroot+0x63>
lea    0xe86(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11a3 <squareroot+0x63>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rdx
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <squareroot+0xf1>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1209 <squareroot+0xc9>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1209 <squareroot+0xc9>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <sqrt@plt>
mov    -0x38(%rbp),%rsi
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<squareroot>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
test   %rdi,%rdi
je     11af <squareroot+0x6f>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11b6 <squareroot+0x76>
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,%r14
mov    0x8(%rsp),%rdx
test   %rdx,%rdx
je     1196 <squareroot+0x56>
cmpb   $0x0,(%rdx)
je     1196 <squareroot+0x56>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1060 <sqrt@plt>
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
jmp    11d3 <squareroot+0x93>
lea    0xe6a(%rip),%rbx
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"error: invalid argument, \22%s\22.\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@.str.2 = [33 x i8] c"warning: trailing garbage \22%s\22.\0A\00"
@.str.3 = [25 x i8] c"Square root of %s is %f\0A\00"
define i32 @squareroot(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
store i8* null, i8** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %8, %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load i8*, i8** %3
br label %20
19: ; preds = %13
br label %20
20: ; preds = %19, %17
%21 = phi i8* [ %18, %17 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %19 ]
%22 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 -1, i32* %2
br label %42
23: ; preds = %8
%24 = load i8*, i8** %3
%25 = call i64 @strtol(i8* %24, i8** %4, i32 0)
store i64 %25, i64* %5
%26 = load i8*, i8** %4
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %4
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %33, %28, %23
%38 = load i8*, i8** %3
%39 = load i64, i64* %5
%40 = call double @sqrt(i64 %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %38, double %40)
store i32 0, i32* %2
br label %42
42: ; preds = %37, %20
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"error: invalid argument, \22%s\22.\0A\00"
@.str.1 = [7 x i8] c"(null)\00"
@.str.2 = [33 x i8] c"warning: trailing garbage \22%s\22.\0A\00"
@.str.3 = [25 x i8] c"Square root of %s is %f\0A\00"
define i32 @squareroot(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = icmp eq i8* %0, null
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5, %1
%9 = phi i8* [ %0, %5 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %1 ]
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %25
12: ; preds = %5
%13 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%14 = load i8*, i8** %2
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %12
%17 = load i8, i8* %14
%18 = icmp eq i8 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %22
22: ; preds = %19, %16, %12
%23 = tail call double @sqrt(i64 %13)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %0, double %23)
br label %25
25: ; preds = %22, %8
%26 = phi i32 [ -1, %8 ], [ 0, %22 ]
ret i32 %26
}