#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*/ printf(char *, ...);
int snprintf(char *, int, char const *, double);
scalar_t__ strcmp(char *, char const *);
int test_dec_in_one_mode(double d, const char *fmt, const char *expected,
                         const char *mode_name) {
  char buf[100];
  int ret = snprintf(buf, sizeof buf, fmt, d);
  if (ret <= 0 || ret >= (int)sizeof buf) {
    printf("snprintf for %a returned %d\n", d, ret);
    return 1;
  }
  if (strcmp(buf, expected) == 0)
    return 0;
  else {
    printf("snprintf (\"%s\", %a) returned \"%s\" not \"%s\" (%s)\n", fmt, d,
           buf, expected, mode_name);
    return 1;
  }
}


x86 assembly (clang, -O0):
<test_dec_in_one_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movsd  -0x10(%rbp),%xmm0
mov    $0x64,%esi
call   1040 <snprintf@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jle    1186 <test_dec_in_one_mode+0x56>
cmpl   $0x64,-0x94(%rbp)
jl     11ab <test_dec_in_one_mode+0x7b>
movsd  -0x10(%rbp),%xmm0
mov    -0x94(%rbp),%esi
lea    0xe68(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fe <test_dec_in_one_mode+0xce>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <test_dec_in_one_mode+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    11fe <test_dec_in_one_mode+0xce>
mov    -0x18(%rbp),%rsi
movsd  -0x10(%rbp),%xmm0
lea    -0x90(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe2d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_dec_in_one_mode>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    %rbx,%rdx
movsd  %xmm0,0x8(%rsp)
call   1040 <snprintf@plt>
lea    -0x64(%rax),%ecx
cmp    $0xffffff9c,%ecx
ja     117d <test_dec_in_one_mode+0x4d>
lea    0xe94(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11b1 <test_dec_in_one_mode+0x81>
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b8 <test_dec_in_one_mode+0x88>
lea    0xe87(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %rbx,%rsi
movsd  0x8(%rsp),%xmm0
mov    %r15,%rcx
mov    %r14,%r8
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x1,%eax
jmp    11ba <test_dec_in_one_mode+0x8a>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"snprintf for %a returned %d\0A\00"
@.str.1 = [49 x i8] c"snprintf (\22%s\22, %a) returned \22%s\22 not \22%s\22 (%s)\0A\00"
define i32 @test_dec_in_one_mode(double %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [100 x i8]
%11 = alloca i32
store double %0, double* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%13 = load i8*, i8** %7
%14 = load double, double* %6
%15 = call i32 @snprintf(i8* %12, i32 100, i8* %13, double %14)
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = icmp sle i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %4
%19 = load i32, i32* %11
%20 = icmp sge i32 %19, 100
br i1 %20, label %21, label %25
21: ; preds = %18, %4
%22 = load double, double* %6
%23 = load i32, i32* %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %22, i32 %23)
store i32 1, i32* %5
br label %38
25: ; preds = %18
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%27 = load i8*, i8** %8
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %5
br label %38
31: ; preds = %25
%32 = load i8*, i8** %7
%33 = load double, double* %6
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%35 = load i8*, i8** %8
%36 = load i8*, i8** %9
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %32, double %33, i8* %34, i8* %35, i8* %36)
store i32 1, i32* %5
br label %38
38: ; preds = %31, %30, %21
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
@.str = [29 x i8] c"snprintf for %a returned %d\0A\00"
@.str.1 = [49 x i8] c"snprintf (\22%s\22, %a) returned \22%s\22 not \22%s\22 (%s)\0A\00"
define i32 @test_dec_in_one_mode(double %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 100, i8* %1, double %0)
%8 = add i32 %7, -100
%9 = icmp ult i32 %8, -99
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), double %0, i32 %7)
br label %17
12: ; preds = %4
%13 = call i64 @strcmp(i8* %6, i8* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %1, double %0, i8* %6, i8* %2, i8* %3)
br label %17
17: ; preds = %12, %15, %10
%18 = phi i32 [ 1, %10 ], [ 1, %15 ], [ 0, %12 ]
ret i32 %18
}