#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_hex_in_one_mode(double d, const char *fmt, const char *expected[4],
                         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]) == 0 || strcmp(buf, expected[1]) == 0 ||
      strcmp(buf, expected[2]) == 0 || strcmp(buf, expected[3]) == 0)
    return 0;
  else {
    printf("snprintf (\"%s\", %a) returned \"%s\" not "
           "\"%s\" or \"%s\" or \"%s\" or \"%s\" (%s)\n",
           fmt, d, buf, expected[0], expected[1], expected[2], expected[3],
           mode_name);
    return 1;
  }
}


x86 assembly (clang, -O0):
<test_hex_in_one_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%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_hex_in_one_mode+0x56>
cmpl   $0x64,-0x94(%rbp)
jl     11ab <test_hex_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    127f <test_hex_in_one_mode+0x14f>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1222 <test_hex_in_one_mode+0xf2>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1222 <test_hex_in_one_mode+0xf2>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1222 <test_hex_in_one_mode+0xf2>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    122e <test_hex_in_one_mode+0xfe>
movl   $0x0,-0x4(%rbp)
jmp    127f <test_hex_in_one_mode+0x14f>
mov    -0x18(%rbp),%rsi
movsd  -0x10(%rbp),%xmm0
lea    -0x90(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r9
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%r10
mov    -0x28(%rbp),%rax
lea    0xdb5(%rip),%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_hex_in_one_mode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    %r15,%rdx
movsd  %xmm0,0x8(%rsp)
call   1040 <snprintf@plt>
lea    -0x64(%rax),%ecx
cmp    $0xffffff9c,%ecx
ja     1183 <test_hex_in_one_mode+0x53>
lea    0xe96(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x1,%ebp
jmp    1205 <test_hex_in_one_mode+0xd5>
mov    (%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1205 <test_hex_in_one_mode+0xd5>
mov    0x8(%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1205 <test_hex_in_one_mode+0xd5>
mov    0x10(%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1205 <test_hex_in_one_mode+0xd5>
mov    0x18(%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1205 <test_hex_in_one_mode+0xd5>
mov    (%rbx),%rcx
mov    0x8(%rbx),%r8
mov    0x10(%rbx),%r9
lea    0xe3b(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %r15,%rsi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
push   %r14
push   0x18(%rbx)
call   1030 <printf@plt>
add    $0x10,%rsp
jmp    1179 <test_hex_in_one_mode+0x49>
mov    %ebp,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"snprintf for %a returned %d\0A\00"
@.str.1 = [73 x i8] c"snprintf (\22%s\22, %a) returned \22%s\22 not \22%s\22 or \22%s\22 or \22%s\22 or \22%s\22 (%s)\0A\00"
define i32 @test_hex_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 %72
25: ; preds = %18
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%27 = load i8**, i8*** %8
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %26, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %53, label %32
32: ; preds = %25
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%34 = load i8**, i8*** %8
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %33, i8* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %53, label %39
39: ; preds = %32
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%41 = load i8**, i8*** %8
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i64 @strcmp(i8* %40, i8* %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %53, label %46
46: ; preds = %39
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%48 = load i8**, i8*** %8
%49 = getelementptr inbounds i8*, i8** %48, i64 3
%50 = load i8*, i8** %49
%51 = call i64 @strcmp(i8* %47, i8* %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %46, %39, %32, %25
store i32 0, i32* %5
br label %72
54: ; preds = %46
%55 = load i8*, i8** %7
%56 = load double, double* %6
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%58 = load i8**, i8*** %8
%59 = getelementptr inbounds i8*, i8** %58, i64 0
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %8
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = load i8**, i8*** %8
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = load i8*, i8** %65
%67 = load i8**, i8*** %8
%68 = getelementptr inbounds i8*, i8** %67, i64 3
%69 = load i8*, i8** %68
%70 = load i8*, i8** %9
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0), i8* %55, double %56, i8* %57, i8* %60, i8* %63, i8* %66, i8* %69, i8* %70)
store i32 1, i32* %5
br label %72
72: ; preds = %54, %53, %21
%73 = load i32, i32* %5
ret i32 %73
}

LLVM IR (-O2):
@.str = [29 x i8] c"snprintf for %a returned %d\0A\00"
@.str.1 = [73 x i8] c"snprintf (\22%s\22, %a) returned \22%s\22 not \22%s\22 or \22%s\22 or \22%s\22 or \22%s\22 (%s)\0A\00"
define i32 @test_hex_in_one_mode(double %0, i8* %1, i8** nocapture %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 %37
12: ; preds = %4
%13 = load i8*, i8** %2
%14 = call i64 @strcmp(i8* %6, i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %37, label %16
16: ; preds = %12
%17 = getelementptr inbounds i8*, i8** %2, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %6, i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %37, label %21
21: ; preds = %16
%22 = getelementptr inbounds i8*, i8** %2, i64 2
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* %6, i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %37, label %26
26: ; preds = %21
%27 = getelementptr inbounds i8*, i8** %2, i64 3
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %6, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %26
%32 = load i8*, i8** %2
%33 = load i8*, i8** %17
%34 = load i8*, i8** %22
%35 = load i8*, i8** %27
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0), i8* %1, double %0, i8* %6, i8* %32, i8* %33, i8* %34, i8* %35, i8* %3)
br label %37
37: ; preds = %12, %16, %21, %26, %31, %10
%38 = phi i32 [ 1, %10 ], [ 1, %31 ], [ 0, %26 ], [ 0, %21 ], [ 0, %16 ], [ 0, %12 ]
ret i32 %38
}