#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 */
scalar_t__ method(char *);
int /*<<< orphan*/ mstring(char *, char *);
int /*<<< orphan*/ printf(char *, char *, double);
void test(char *src) {
  char buffer[41] = "";
  const int tests = 100000;
  int sum = 0;
  int t;
  double pc;
  for (t = 0; t < tests; t++) {
    sum += method(src);
  }
  mstring(src, buffer);
  pc = 100.0 * sum / tests;
  printf("%-40s produces %6.3f%% deaths.\n", buffer, pc);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x29,%edx
call   1050 <memset@plt>
movl   $0x186a0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x186a0,-0x4c(%rbp)
jge    11a2 <test+0x62>
mov    -0x8(%rbp),%rdi
call   1040 <method@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1171 <test+0x31>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <mstring@plt>
cvtsi2sdl -0x48(%rbp),%xmm1
movsd  0xe4c(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe38(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
lea    -0x40(%rbp),%rsi
movsd  -0x58(%rbp),%xmm0
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movups %xmm0,0x19(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %ebp,%ebp
mov    $0x186a0,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1040 <method@plt>
add    %eax,%ebp
add    $0xffffffff,%ebx
jne    1160 <test+0x30>
mov    %rsp,%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <mstring@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe74(%rip),%xmm0
divsd  0xe74(%rip),%xmm0
lea    0xe75(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"%-40s produces %6.3f%% deaths.\0A\00"
define void @test(i8* %0) {
%2 = alloca i8*
%3 = alloca [41 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store i8* %0, i8** %2
%8 = bitcast [41 x i8]* %3 to i8*
store i32 100000, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %19, %1
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 100000
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i8*, i8** %2
%14 = call i64 @method(i8* %13)
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = add nsw i64 %16, %14
%18 = trunc i64 %17 to i32
store i32 %18, i32* %5
br label %19
19: ; preds = %12
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %9
22: ; preds = %9
%23 = load i8*, i8** %2
%24 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
%25 = call i32 @mstring(i8* %23, i8* %24)
%26 = load i32, i32* %5
%27 = sitofp i32 %26 to double
%28 = fmul double 1.000000e+02, %27
%29 = fdiv double %28, 1.000000e+05
store double %29, double* %7
%30 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
%31 = load double, double* %7
%32 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %30, double %31)
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"%-40s produces %6.3f%% deaths.\0A\00"
define void @test(i8* %0) {
%2 = alloca [41 x i8]
%3 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %1, %4
%5 = phi i32 [ 0, %1 ], [ %9, %4 ]
%6 = phi i32 [ 0, %1 ], [ %10, %4 ]
%7 = tail call i64 @method(i8* %0)
%8 = trunc i64 %7 to i32
%9 = add i32 %5, %8
%10 = add nuw nsw i32 %6, 1
%11 = icmp eq i32 %10, 100000
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = call i32 @mstring(i8* %0, i8* %3)
%14 = sitofp i32 %9 to double
%15 = fmul double %14, 1.000000e+02
%16 = fdiv double %15, 1.000000e+05
%17 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %3, double %16)
ret void
}