#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 */
typedef char wchar_t;
struct rlimit {
  long rlim_cur;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_AS;
long RLIM_INFINITY;
int asprintf(char **, char *, int);
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ mtrace();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int swprintf(char *, int, char *, int);
int do_test(void) {
  mtrace();
  int ret;
  {
    char *result;
    ret = asprintf(&result, "%133000.133001x", 17);
    if (ret < 0) {
      printf("error: asprintf: %m\n");
      return 1;
    }
    free(result);
  }
  {
    wchar_t *result = calloc(ret + 1, sizeof(wchar_t));
    if (result == NULL) {
      printf("error: calloc (%d, %zu): %m", ret + 1, sizeof(wchar_t));
      return 1;
    }
    ret = swprintf(result, ret + 1, L"%133000.133001x", 17);
    if (ret < 0) {
      printf("error: swprintf: %d (%m)\n", ret);
      return 1;
    }
    free(result);
  }
  {
    struct rlimit limit;
    if (getrlimit(RLIMIT_AS, &limit) != 0) {
      printf("getrlimit (RLIMIT_AS) failed: %m\n");
      return 1;
    }
    long target = 200 * 1024 * 1024;
    if (limit.rlim_cur == RLIM_INFINITY || limit.rlim_cur > target) {
      limit.rlim_cur = target;
      if (setrlimit(RLIMIT_AS, &limit) != 0) {
        printf("setrlimit (RLIMIT_AS) failed: %m\n");
        return 1;
      }
    }
  }
  {
    char *result;
    ret = asprintf(&result, "%133000.999999999x", 17);
    if (ret >= 0) {
      printf("error: asprintf: incorrect result %d\n", ret);
      return 1;
    }
  }
  {
    wchar_t result[100];
    if (result == NULL) {
      printf("error: calloc (%d, %zu): %m", ret + 1, sizeof(wchar_t));
      return 1;
    }
    ret = swprintf(result, 100, L"%133000.999999999x", 17);
    if (ret >= 0) {
      printf("error: swprintf: incorrect result %d\n", ret);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    $0x0,%al
call   1090 <mtrace@plt>
lea    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x11,%edx
call   1080 <asprintf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ce <do_test+0x4e>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1399 <do_test+0x219>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121b <do_test+0x9b>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
lea    0xe22(%rip),%rdi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1399 <do_test+0x219>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
lea    0xed4(%rip),%rdx
mov    $0x11,%ecx
call   1060 <swprintf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1260 <do_test+0xe0>
mov    -0x8(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1399 <do_test+0x219>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   10a0 <getrlimit@plt>
cmp    $0x0,%rax
je     129f <do_test+0x11f>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1399 <do_test+0x219>
movq   $0xc800000,-0x28(%rbp)
0c
mov    -0x20(%rbp),%rax
mov    0x2d26(%rip),%rcx
cmp    (%rcx),%rax
je     12c9 <do_test+0x149>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    130c <do_test+0x18c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1070 <setrlimit@plt>
cmp    $0x0,%rax
je     1307 <do_test+0x187>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1399 <do_test+0x219>
jmp    130c <do_test+0x18c>
lea    -0x30(%rbp),%rdi
lea    0xd88(%rip),%rsi
mov    $0x11,%edx
call   1080 <asprintf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     134b <do_test+0x1cb>
mov    -0x8(%rbp),%esi
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1399 <do_test+0x219>
lea    -0xa0(%rbp),%rdi
mov    $0x64,%esi
lea    0xde2(%rip),%rdx
mov    $0x11,%ecx
call   1060 <swprintf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1392 <do_test+0x212>
mov    -0x8(%rbp),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1399 <do_test+0x219>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
xor    %eax,%eax
call   1090 <mtrace@plt>
lea    0xe6a(%rip),%rsi
mov    %rsp,%rdi
mov    $0x11,%edx
call   1080 <asprintf@plt>
test   %eax,%eax
js     1210 <do_test+0x90>
mov    %eax,%ebp
mov    (%rsp),%rdi
call   1030 <free@plt>
add    $0x1,%ebp
mov    $0x1,%r14d
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     1223 <do_test+0xa3>
mov    %rax,%rbx
lea    0xf2a(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x11,%ecx
call   1060 <swprintf@plt>
test   %eax,%eax
js     123a <do_test+0xba>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2de8(%rip),%rbx
mov    (%rbx),%edi
mov    %rsp,%rsi
call   10a0 <getrlimit@plt>
test   %rax,%rax
je     1243 <do_test+0xc3>
lea    0xe4d(%rip),%rdi
jmp    1217 <do_test+0x97>
lea    0xdf9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12a3 <do_test+0x123>
lea    0xdfb(%rip),%rdi
mov    $0x1,%edx
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12a9 <do_test+0x129>
lea    0xe00(%rip),%rdi
jmp    129a <do_test+0x11a>
mov    (%rsp),%rax
cmp    $0xc800000,%rax
jg     125b <do_test+0xdb>
mov    0x2d82(%rip),%rcx
cmp    (%rcx),%rax
jne    127b <do_test+0xfb>
movq   $0xc800000,(%rsp)
0c
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1070 <setrlimit@plt>
test   %rax,%rax
je     127b <do_test+0xfb>
lea    0xe04(%rip),%rdi
jmp    1217 <do_test+0x97>
lea    0xe1d(%rip),%rsi
mov    %rsp,%rdi
mov    $0x11,%edx
call   1080 <asprintf@plt>
test   %eax,%eax
js     12b5 <do_test+0x135>
lea    0xe18(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe84(%rip),%rdx
mov    %rsp,%rdi
mov    $0x64,%esi
mov    $0x11,%ecx
call   1060 <swprintf@plt>
mov    %eax,%r14d
test   %eax,%eax
js     12e6 <do_test+0x166>
lea    0xdfc(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
not    %r14d
shr    $0x1f,%r14d
jmp    12a9 <do_test+0x129>

LLVM IR (-O0):
%struct.rlimit = type { i64 }
@.str = [16 x i8] c"%133000.133001x\00"
@.str.1 = [21 x i8] c"error: asprintf: %m\0A\00"
@.str.2 = [28 x i8] c"error: calloc (%d, %zu): %m\00"
@.str.3 = [16 x i32] [i32 37, i32 49, i32 51, i32 51, i32 48, i32 48, i32 48, i32 46, i32 49, i32 51, i32 51, i32 48, i32 48, i32 49, i32 120, i32 0]
@.str.4 = [26 x i8] c"error: swprintf: %d (%m)\0A\00"
@RLIMIT_AS = global i32 0
@.str.5 = [34 x i8] c"getrlimit (RLIMIT_AS) failed: %m\0A\00"
@RLIM_INFINITY = global i64 0
@.str.6 = [34 x i8] c"setrlimit (RLIMIT_AS) failed: %m\0A\00"
@.str.7 = [19 x i8] c"%133000.999999999x\00"
@.str.8 = [38 x i8] c"error: asprintf: incorrect result %d\0A\00"
@.str.9 = [19 x i32] [i32 37, i32 49, i32 51, i32 51, i32 48, i32 48, i32 48, i32 46, i32 57, i32 57, i32 57, i32 57, i32 57, i32 57, i32 57, i32 57, i32 57, i32 120, i32 0]
@.str.10 = [38 x i8] c"error: swprintf: incorrect result %d\0A\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.rlimit
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [100 x i8]
%9 = call i32 (...) @mtrace()
%10 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 17)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %80
15: ; preds = %0
%16 = load i8*, i8** %3
%17 = call i32 @free(i8* %16)
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
%20 = call i8* @calloc(i32 %19, i32 1)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %25, i64 1)
store i32 1, i32* %1
br label %80
27: ; preds = %15
%28 = load i8*, i8** %4
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
%31 = call i32 @swprintf(i8* %28, i32 %30, i8* bitcast ([16 x i32]* @.str.3 to i8*), i32 17)
store i32 %31, i32* %2
%32 = load i32, i32* %2
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = load i32, i32* %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %35)
store i32 1, i32* %1
br label %80
37: ; preds = %27
%38 = load i8*, i8** %4
%39 = call i32 @free(i8* %38)
%40 = load i32, i32* @RLIMIT_AS
%41 = call i64 @getrlimit(i32 %40, %struct.rlimit* %5)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %80
45: ; preds = %37
store i64 209715200, i64* %6
%46 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%47 = load i64, i64* %46
%48 = load i64, i64* @RLIM_INFINITY
%49 = icmp eq i64 %47, %48
br i1 %49, label %55, label %50
50: ; preds = %45
%51 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%52 = load i64, i64* %51
%53 = load i64, i64* %6
%54 = icmp sgt i64 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %50, %45
%56 = load i64, i64* %6
%57 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
store i64 %56, i64* %57
%58 = load i32, i32* @RLIMIT_AS
%59 = call i64 @setrlimit(i32 %58, %struct.rlimit* %5)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %80
63: ; preds = %55
br label %64
64: ; preds = %63, %50
%65 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 17)
store i32 %65, i32* %2
%66 = load i32, i32* %2
%67 = icmp sge i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = load i32, i32* %2
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i32 %69)
store i32 1, i32* %1
br label %80
71: ; preds = %64
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%73 = call i32 @swprintf(i8* %72, i32 100, i8* bitcast ([19 x i32]* @.str.9 to i8*), i32 17)
store i32 %73, i32* %2
%74 = load i32, i32* %2
%75 = icmp sge i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load i32, i32* %2
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.10, i64 0, i64 0), i32 %77)
store i32 1, i32* %1
br label %80
79: ; preds = %71
store i32 0, i32* %1
br label %80
80: ; preds = %79, %76, %68, %61, %43, %34, %23, %13
%81 = load i32, i32* %1
ret i32 %81
}

LLVM IR (-O2):
%struct.rlimit = type { i64 }
@.str = [16 x i8] c"%133000.133001x\00"
@.str.1 = [21 x i8] c"error: asprintf: %m\0A\00"
@.str.2 = [28 x i8] c"error: calloc (%d, %zu): %m\00"
@.str.3 = [16 x i32] [i32 37, i32 49, i32 51, i32 51, i32 48, i32 48, i32 48, i32 46, i32 49, i32 51, i32 51, i32 48, i32 48, i32 49, i32 120, i32 0]
@.str.4 = [26 x i8] c"error: swprintf: %d (%m)\0A\00"
@RLIMIT_AS = global i32 0
@.str.5 = [34 x i8] c"getrlimit (RLIMIT_AS) failed: %m\0A\00"
@RLIM_INFINITY = global i64 0
@.str.6 = [34 x i8] c"setrlimit (RLIMIT_AS) failed: %m\0A\00"
@.str.7 = [19 x i8] c"%133000.999999999x\00"
@.str.8 = [38 x i8] c"error: asprintf: incorrect result %d\0A\00"
@.str.9 = [19 x i32] [i32 37, i32 49, i32 51, i32 51, i32 48, i32 48, i32 48, i32 46, i32 57, i32 57, i32 57, i32 57, i32 57, i32 57, i32 57, i32 57, i32 57, i32 120, i32 0]
@.str.10 = [38 x i8] c"error: swprintf: incorrect result %d\0A\00"
define i32 @do_test() {
%1 = alloca i8*
%2 = alloca %struct.rlimit
%3 = alloca i8*
%4 = alloca [100 x i8]
%5 = tail call i32 (...) @mtrace()
%6 = bitcast i8** %1 to i8*
%7 = call i32 @asprintf(i8** %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 17)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %59
11: ; preds = %0
%12 = load i8*, i8** %1
%13 = call i32 @free(i8* %12)
%14 = add nuw nsw i32 %7, 1
%15 = call i8* @calloc(i32 %14, i32 1)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %14, i64 1)
br label %59
19: ; preds = %11
%20 = call i32 @swprintf(i8* %15, i32 %14, i8* bitcast ([16 x i32]* @.str.3 to i8*), i32 17)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %59
24: ; preds = %19
%25 = call i32 @free(i8* %15)
%26 = bitcast %struct.rlimit* %2 to i8*
%27 = load i32, i32* @RLIMIT_AS
%28 = call i64 @getrlimit(i32 %27, %struct.rlimit* %2)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %24
%31 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
%32 = load i64, i64* %31
%33 = load i64, i64* @RLIM_INFINITY
%34 = icmp eq i64 %32, %33
%35 = icmp sgt i64 %32, 209715200
%36 = or i1 %35, %34
br i1 %36, label %37, label %44
37: ; preds = %30
store i64 209715200, i64* %31
%38 = load i32, i32* @RLIMIT_AS
%39 = call i64 @setrlimit(i32 %38, %struct.rlimit* %2)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %37, %24
%42 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), %24 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), %37 ]
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %42)
br label %59
44: ; preds = %30, %37
%45 = bitcast i8** %3 to i8*
%46 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 17)
%47 = icmp sgt i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i32 %46)
br label %59
50: ; preds = %44
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%52 = call i32 @swprintf(i8* %51, i32 100, i8* bitcast ([19 x i32]* @.str.9 to i8*), i32 17)
%53 = icmp sgt i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.10, i64 0, i64 0), i32 %52)
br label %56
56: ; preds = %50, %54
%57 = xor i32 %52, -1
%58 = lshr i32 %57, 31
br label %59
59: ; preds = %41, %9, %56, %48, %17, %22
%60 = phi i32 [ 1, %48 ], [ 1, %41 ], [ 1, %22 ], [ 1, %17 ], [ %58, %56 ], [ 1, %9 ]
ret i32 %60
}