void test3(void) {
  int a = 1;
  int b = 2;
  __asm__("add $2, %1 \n\t"
          "mov %1, %0 \n\t"
          : "=r"(a)
          : "r"(b));
  assert(b == 2);
  assert(a == 4);
  __asm__("add $2, %1 \n\t"
          "mov %1, %0 \n\t"
          : "=r"(a), "+r"(b)
          :);
  assert(b == 4);
  assert(a == 4);
}


x86 assembly (clang, -O0):
<test3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
cmpl   $0x4,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,%ecx
mov    %ecx,-0x4(%rbp)
mov    %eax,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
cmpl   $0x4,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test3>:
push   %rbp
push   %rbx
push   %rax
mov    $0x2,%ebx
add    $0x2,%ebx
mov    %ebx,%ebp
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x4,%ebp
sete   %dil
xor    %eax,%eax
call   1030 <assert@plt>
add    $0x2,%ebx
mov    %ebx,%ebp
xor    %edi,%edi
cmp    $0x4,%ebx
sete   %dil
xor    %eax,%eax
call   1030 <assert@plt>
xor    %edi,%edi
cmp    $0x4,%ebp
sete   %dil
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <assert@plt>

LLVM IR (-O0):
define void @test3() {
%1 = alloca i32
%2 = alloca i32
store i32 1, i32* %1
store i32 2, i32* %2
%3 = load i32, i32* %2
%4 = call i32 asm "add $$2, $1 \0A\09mov $1, $0 \0A\09", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %3)
store i32 %4, i32* %1
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 2
%7 = zext i1 %6 to i32
%8 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %7)
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 4
%11 = zext i1 %10 to i32
%12 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %11)
%13 = load i32, i32* %2
%14 = call { i32, i32 } asm "add $$2, $1 \0A\09mov $1, $0 \0A\09", "=r,=r,1,~{dirflag},~{fpsr},~{flags}"(i32 %13)
%15 = extractvalue { i32, i32 } %14, 0
%16 = extractvalue { i32, i32 } %14, 1
store i32 %15, i32* %1
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 4
%19 = zext i1 %18 to i32
%20 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %19)
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, 4
%23 = zext i1 %22 to i32
%24 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %23)
ret void
}

LLVM IR (-O2):
define void @test3() {
%1 = tail call i32 asm "add $$2, $1 \0A\09mov $1, $0 \0A\09", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 2)
%2 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 1)
%3 = icmp eq i32 %1, 4
%4 = zext i1 %3 to i32
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %4)
%6 = tail call { i32, i32 } asm "add $$2, $1 \0A\09mov $1, $0 \0A\09", "=r,=r,1,~{dirflag},~{fpsr},~{flags}"(i32 2)
%7 = extractvalue { i32, i32 } %6, 0
%8 = extractvalue { i32, i32 } %6, 1
%9 = icmp eq i32 %8, 4
%10 = zext i1 %9 to i32
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %10)
%12 = icmp eq i32 %7, 4
%13 = zext i1 %12 to i32
%14 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %13)
ret void
}