#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ b2;
typedef int /*<<< orphan*/ b1;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int memcmp(char *, char *, scalar_t__);
int pack_str(char *, scalar_t__ *, int, char *);
int repack_str(char *, scalar_t__ *, int, char *, scalar_t__ *, int);
int /*<<< orphan*/ stderr;
int test_repack_str(void) {
  char b1[128] = {0}, b2[128] = {0};
  uint32_t o1, o2;
  o1 = 0;
  do {
    int __my_ret__ = pack_str(b1, &o1, sizeof(b1), "abc");
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 116,
              "pack_str(b1, &o1, sizeof(b1), \"abc\")");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = pack_str(b1, &o1, sizeof(b1), "def");
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 117,
              "pack_str(b1, &o1, sizeof(b1), \"def\")");
      return __my_ret__;
    }
  } while (0);
  ;
  o1 = 0;
  o2 = 0;
  do {
    int __my_ret__ = repack_str(b2, &o2, sizeof(b2), b1, &o1, sizeof(b1));
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 120,
              "repack_str(b2, &o2, sizeof(b2), b1, &o1, sizeof(b1))");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = repack_str(b2, &o2, sizeof(b2), b1, &o1, sizeof(b1));
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 122,
              "repack_str(b2, &o2, sizeof(b2), b1, &o1, sizeof(b1))");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    if ((o1) != (o2)) {
      fprintf(stderr, "failed on line %d: %s\n", 124, "o1");
      return 1;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = memcmp(b1, b2, o1);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 125, "memcmp(b1, b2, o1)");
      return __my_ret__;
    }
  } while (0);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<test_repack_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
movq   $0x0,-0x118(%rbp)
lea    -0x90(%rbp),%rdi
lea    -0x118(%rbp),%rsi
mov    $0x80,%edx
lea    0xe5a(%rip),%rcx
call   1070 <pack_str@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     11ed <test_repack_str+0x9d>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
mov    $0x74,%edx
lea    0xe41(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1412 <test_repack_str+0x2c2>
jmp    11f2 <test_repack_str+0xa2>
jmp    11f7 <test_repack_str+0xa7>
lea    -0x90(%rbp),%rdi
lea    -0x118(%rbp),%rsi
mov    $0x80,%edx
lea    0xe2f(%rip),%rcx
call   1070 <pack_str@plt>
mov    %eax,-0x128(%rbp)
cmpl   $0x0,-0x128(%rbp)
je     1258 <test_repack_str+0x108>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
mov    $0x75,%edx
lea    0xdff(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x128(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1412 <test_repack_str+0x2c2>
jmp    125d <test_repack_str+0x10d>
movq   $0x0,-0x118(%rbp)
movq   $0x0,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
lea    -0x90(%rbp),%rcx
lea    -0x120(%rbp),%rsi
mov    $0x80,%r9d
lea    -0x118(%rbp),%r8
mov    %r9d,%edx
call   1060 <repack_str@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x12c(%rbp)
je     12df <test_repack_str+0x18f>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd44(%rip),%rsi
mov    $0x78,%edx
lea    0xd9d(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x12c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1412 <test_repack_str+0x2c2>
jmp    12e4 <test_repack_str+0x194>
jmp    12e9 <test_repack_str+0x199>
lea    -0x110(%rbp),%rdi
lea    -0x90(%rbp),%rcx
lea    -0x120(%rbp),%rsi
mov    $0x80,%r9d
lea    -0x118(%rbp),%r8
mov    %r9d,%edx
call   1060 <repack_str@plt>
mov    %eax,-0x130(%rbp)
cmpl   $0x0,-0x130(%rbp)
je     1355 <test_repack_str+0x205>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
lea    0xcce(%rip),%rsi
mov    $0x7a,%edx
lea    0xd27(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x130(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1412 <test_repack_str+0x2c2>
jmp    135a <test_repack_str+0x20a>
jmp    135f <test_repack_str+0x20f>
mov    -0x118(%rbp),%rax
cmp    -0x120(%rbp),%rax
je     13a0 <test_repack_str+0x250>
mov    0x2c66(%rip),%rax
mov    (%rax),%edi
lea    0xc81(%rip),%rsi
mov    $0x7c,%edx
lea    0xd0f(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1412 <test_repack_str+0x2c2>
jmp    13a5 <test_repack_str+0x255>
jmp    13aa <test_repack_str+0x25a>
lea    -0x90(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    -0x118(%rbp),%rdx
call   1040 <memcmp@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
je     1406 <test_repack_str+0x2b6>
mov    0x2c02(%rip),%rax
mov    (%rax),%edi
lea    0xc1d(%rip),%rsi
mov    $0x7d,%edx
lea    0xcae(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1412 <test_repack_str+0x2c2>
jmp    140b <test_repack_str+0x2bb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_repack_str>:
push   %rbx
sub    $0x110,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movq   $0x0,(%rsp)
lea    0xe3b(%rip),%rcx
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x80,%edx
call   1060 <pack_str@plt>
test   %eax,%eax
je     11fe <test_repack_str+0xbe>
mov    %eax,%ebx
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
lea    0xe27(%rip),%rcx
mov    $0x74,%edx
jmp    12df <test_repack_str+0x19f>
lea    0xe3b(%rip),%rcx
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x80,%edx
call   1060 <pack_str@plt>
test   %eax,%eax
je     123e <test_repack_str+0xfe>
mov    %eax,%ebx
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
lea    0xe10(%rip),%rcx
mov    $0x75,%edx
jmp    12df <test_repack_str+0x19f>
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x90(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %rsp,%r8
mov    $0x80,%edx
mov    $0x80,%r9d
call   1050 <repack_str@plt>
test   %eax,%eax
je     1298 <test_repack_str+0x158>
mov    %eax,%ebx
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
lea    0xdd8(%rip),%rcx
mov    $0x78,%edx
jmp    12df <test_repack_str+0x19f>
lea    0x90(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %rsp,%r8
mov    $0x80,%edx
mov    $0x80,%r9d
call   1050 <repack_str@plt>
test   %eax,%eax
je     12ef <test_repack_str+0x1af>
mov    %eax,%ebx
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
lea    0xd31(%rip),%rsi
lea    0xd8f(%rip),%rcx
mov    $0x7a,%edx
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x110,%rsp
pop    %rbx
ret
mov    (%rsp),%rdx
cmp    0x8(%rsp),%rdx
jne    1330 <test_repack_str+0x1f0>
lea    0x10(%rsp),%rdi
lea    0x90(%rsp),%rsi
call   1030 <memcmp@plt>
test   %eax,%eax
je     1358 <test_repack_str+0x218>
mov    %eax,%ebx
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
lea    0xce2(%rip),%rsi
lea    0xd78(%rip),%rcx
mov    $0x7d,%edx
jmp    12df <test_repack_str+0x19f>
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
lea    0xcc4(%rip),%rsi
lea    0xd57(%rip),%rcx
mov    $0x7c,%edx
call   1040 <fprintf@plt>
mov    $0x1,%ebx
jmp    12e4 <test_repack_str+0x1a4>
xor    %ebx,%ebx
jmp    12e4 <test_repack_str+0x1a4>

LLVM IR (-O0):
@.str = [4 x i8] c"abc\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [37 x i8] c"pack_str(b1, &o1, sizeof(b1), \22abc\22)\00"
@.str.3 = [4 x i8] c"def\00"
@.str.4 = [37 x i8] c"pack_str(b1, &o1, sizeof(b1), \22def\22)\00"
@.str.5 = [53 x i8] c"repack_str(b2, &o2, sizeof(b2), b1, &o1, sizeof(b1))\00"
@.str.6 = [3 x i8] c"o1\00"
@.str.7 = [19 x i8] c"memcmp(b1, b2, o1)\00"
define i32 @test_repack_str() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = bitcast [128 x i8]* %2 to i8*
%12 = bitcast [128 x i8]* %3 to i8*
store i64 0, i64* %4
br label %13
13: ; preds = %0
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%15 = call i32 @pack_str(i8* %14, i64* %4, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 116, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* %6
store i32 %21, i32* %1
br label %81
22: ; preds = %13
br label %23
23: ; preds = %22
br label %24
24: ; preds = %23
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%26 = call i32 @pack_str(i8* %25, i64* %4, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 117, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* %7
store i32 %32, i32* %1
br label %81
33: ; preds = %24
br label %34
34: ; preds = %33
store i64 0, i64* %4
store i64 0, i64* %5
br label %35
35: ; preds = %34
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%38 = call i32 @repack_str(i8* %36, i64* %5, i32 128, i8* %37, i64* %4, i32 128)
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 120, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* %8
store i32 %44, i32* %1
br label %81
45: ; preds = %35
br label %46
46: ; preds = %45
br label %47
47: ; preds = %46
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%50 = call i32 @repack_str(i8* %48, i64* %5, i32 128, i8* %49, i64* %4, i32 128)
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 122, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0))
%56 = load i32, i32* %9
store i32 %56, i32* %1
br label %81
57: ; preds = %47
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
%60 = load i64, i64* %4
%61 = load i64, i64* %5
%62 = icmp ne i64 %60, %61
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 124, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %81
66: ; preds = %59
br label %67
67: ; preds = %66
br label %68
68: ; preds = %67
%69 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%70 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%71 = load i64, i64* %4
%72 = call i32 @memcmp(i8* %69, i8* %70, i64 %71)
store i32 %72, i32* %10
%73 = load i32, i32* %10
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %68
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 125, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%78 = load i32, i32* %10
store i32 %78, i32* %1
br label %81
79: ; preds = %68
br label %80
80: ; preds = %79
store i32 0, i32* %1
br label %81
81: ; preds = %80, %75, %63, %53, %41, %29, %18
%82 = load i32, i32* %1
ret i32 %82
}

LLVM IR (-O2):
@.str = [4 x i8] c"abc\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [37 x i8] c"pack_str(b1, &o1, sizeof(b1), \22abc\22)\00"
@.str.3 = [4 x i8] c"def\00"
@.str.4 = [37 x i8] c"pack_str(b1, &o1, sizeof(b1), \22def\22)\00"
@.str.5 = [53 x i8] c"repack_str(b2, &o2, sizeof(b2), b1, &o1, sizeof(b1))\00"
@.str.6 = [3 x i8] c"o1\00"
@.str.7 = [19 x i8] c"memcmp(b1, b2, o1)\00"
define i32 @test_repack_str() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%7 = bitcast i64* %3 to i8*
%8 = bitcast i64* %4 to i8*
store i64 0, i64* %3
%9 = call i32 @pack_str(i8* %5, i64* %3, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 116, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %45
14: ; preds = %0
%15 = call i32 @pack_str(i8* %5, i64* %3, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 117, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %45
20: ; preds = %14
store i64 0, i64* %3
store i64 0, i64* %4
%21 = call i32 @repack_str(i8* %6, i64* %4, i32 128, i8* %5, i64* %3, i32 128)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 120, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0))
br label %45
26: ; preds = %20
%27 = call i32 @repack_str(i8* %6, i64* %4, i32 128, i8* %5, i64* %3, i32 128)
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 122, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0))
br label %45
32: ; preds = %26
%33 = load i64, i64* %3
%34 = load i64, i64* %4
%35 = icmp eq i64 %33, %34
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 124, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %45
39: ; preds = %32
%40 = call i32 @memcmp(i8* %5, i8* %6, i64 %33)
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 125, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %45
45: ; preds = %42, %39, %29, %23, %17, %11, %36
%46 = phi i32 [ 1, %36 ], [ %27, %29 ], [ %21, %23 ], [ %15, %17 ], [ %9, %11 ], [ 0, %39 ], [ %40, %42 ]
ret i32 %46
}