void test_inc(int x) {
  volatile int a, b;
  a = b = x;
  __asm__ __volatile__("incl %1\n\t" : "+m"(a));
  __asm__ __volatile__("addl $1, %1\n\t" : "+m"(b));
  do {
    if (!(a == b))
      asm volatile(".byte 0xd6" : : "a"(1));
  } while (0);
  do {
    if (!(a == x + 1))
      asm volatile(".byte 0xd6" : : "a"(1));
  } while (0);
  a = b = x;
  __asm__ __volatile__("incl %1\n\t" : "+a"(a));
  __asm__ __volatile__("addl $1, %1\n\t" : "+a"(b));
  do {
    if (!(a == b))
      asm volatile(".byte 0xd6" : : "a"(1));
  } while (0);
  do {
    if (!(a == x + 1))
      asm volatile(".byte 0xd6" : : "a"(1));
  } while (0);
}


x86 assembly (clang, -O0):
<test_inc>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    %eax,-0x8(%rbp)
incl   -0x8(%rbp)
addl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
cmp    %ecx,%eax
je     112b <test_inc+0x2b>
mov    $0x1,%eax
(bad)
jmp    1130 <test_inc+0x30>
jmp    1135 <test_inc+0x35>
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     114c <test_inc+0x4c>
mov    $0x1,%eax
(bad)
jmp    1151 <test_inc+0x51>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
inc    %eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
cmp    %ecx,%eax
je     117f <test_inc+0x7f>
mov    $0x1,%eax
(bad)
jmp    1184 <test_inc+0x84>
jmp    1189 <test_inc+0x89>
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     11a0 <test_inc+0xa0>
mov    $0x1,%eax
(bad)
jmp    11a5 <test_inc+0xa5>
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_inc>:
mov    %edi,-0x4(%rsp)
mov    %edi,-0x8(%rsp)
incl   -0x8(%rsp)
addl   $0x1,-0x4(%rsp)
mov    -0x8(%rsp),%eax
cmp    -0x4(%rsp),%eax
je     1121 <test_inc+0x21>
mov    $0x1,%eax
(bad)
mov    -0x8(%rsp),%eax
lea    0x1(%rdi),%ecx
cmp    %ecx,%eax
je     1132 <test_inc+0x32>
mov    $0x1,%eax
(bad)
mov    %edi,-0x4(%rsp)
mov    %edi,-0x8(%rsp)
mov    -0x8(%rsp),%eax
inc    %eax
mov    %eax,-0x8(%rsp)
mov    -0x4(%rsp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rsp)
mov    -0x8(%rsp),%eax
cmp    -0x4(%rsp),%eax
je     115f <test_inc+0x5f>
mov    $0x1,%eax
(bad)
mov    -0x8(%rsp),%eax
cmp    %ecx,%eax
je     116d <test_inc+0x6d>
mov    $0x1,%eax
(bad)
ret

LLVM IR (-O0):
define void @test_inc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
store volatile i32 %5, i32* %4
store volatile i32 %5, i32* %3
br label %6
6: ; preds = %1
%7 = load volatile i32, i32* %3
%8 = load volatile i32, i32* %4
%9 = icmp eq i32 %7, %8
br i1 %9, label %11, label %10
10: ; preds = %6
br label %11
11: ; preds = %10, %6
br label %12
12: ; preds = %11
br label %13
13: ; preds = %12
%14 = load volatile i32, i32* %3
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
%17 = icmp eq i32 %14, %16
br i1 %17, label %19, label %18
18: ; preds = %13
br label %19
19: ; preds = %18, %13
br label %20
20: ; preds = %19
%21 = load i32, i32* %2
store volatile i32 %21, i32* %4
store volatile i32 %21, i32* %3
%22 = load volatile i32, i32* %3
%23 = call i32 asm sideeffect "incl $1\0A\09", "={ax},0,~{dirflag},~{fpsr},~{flags}"(i32 %22)
store volatile i32 %23, i32* %3
%24 = load volatile i32, i32* %4
%25 = call i32 asm sideeffect "addl $$1, $1\0A\09", "={ax},0,~{dirflag},~{fpsr},~{flags}"(i32 %24)
store volatile i32 %25, i32* %4
br label %26
26: ; preds = %20
%27 = load volatile i32, i32* %3
%28 = load volatile i32, i32* %4
%29 = icmp eq i32 %27, %28
br i1 %29, label %31, label %30
30: ; preds = %26
br label %31
31: ; preds = %30, %26
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32
%34 = load volatile i32, i32* %3
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
%37 = icmp eq i32 %34, %36
br i1 %37, label %39, label %38
38: ; preds = %33
br label %39
39: ; preds = %38, %33
br label %40
40: ; preds = %39
ret void
}

LLVM IR (-O2):
define void @test_inc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
store volatile i32 %0, i32* %3
store volatile i32 %0, i32* %2
%6 = load volatile i32, i32* %2
%7 = load volatile i32, i32* %3
%8 = icmp eq i32 %6, %7
br i1 %8, label %10, label %9
9: ; preds = %1
br label %10
10: ; preds = %1, %9
%11 = load volatile i32, i32* %2
%12 = add nsw i32 %0, 1
%13 = icmp eq i32 %11, %12
br i1 %13, label %15, label %14
14: ; preds = %10
br label %15
15: ; preds = %14, %10
store volatile i32 %0, i32* %3
store volatile i32 %0, i32* %2
%16 = load volatile i32, i32* %2
%17 = call i32 asm sideeffect "incl $1\0A\09", "={ax},0,~{dirflag},~{fpsr},~{flags}"(i32 %16)
store volatile i32 %17, i32* %2
%18 = load volatile i32, i32* %3
%19 = call i32 asm sideeffect "addl $$1, $1\0A\09", "={ax},0,~{dirflag},~{fpsr},~{flags}"(i32 %18)
store volatile i32 %19, i32* %3
%20 = load volatile i32, i32* %2
%21 = load volatile i32, i32* %3
%22 = icmp eq i32 %20, %21
br i1 %22, label %24, label %23
23: ; preds = %15
br label %24
24: ; preds = %15, %23
%25 = load volatile i32, i32* %2
%26 = icmp eq i32 %25, %12
br i1 %26, label %28, label %27
27: ; preds = %24
br label %28
28: ; preds = %27, %24
ret void
}