#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 */
struct mbox_int {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ abort();
int mbox_get(struct mbox_int *, int *);
int /*<<< orphan*/ printf(char *, int);
int thrd_success;
int consume_thrd(void *arg) {
  struct mbox_int *x = arg;
  for (;;) {
    int v;
    int r = mbox_get(x, &v);
    if (r != thrd_success)
      abort();
    printf("got: %d\n", v);
  }
}


x86 assembly (clang, -O0):
<consume_thrd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <mbox_get@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%eax
je     116d <consume_thrd+0x3d>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x14(%rbp),%esi
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
jmp    1144 <consume_thrd+0x14>

x86 assembly (clang, -O2):
<consume_thrd>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x4(%rsp),%rsi
call   1050 <mbox_get@plt>
mov    0x2e9c(%rip),%r12
cmp    (%r12),%eax
jne    117d <consume_thrd+0x4d>
lea    0xea7(%rip),%r14
lea    0x4(%rsp),%r15
xchg   %ax,%ax
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <mbox_get@plt>
cmp    (%r12),%eax
je     1160 <consume_thrd+0x30>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.mbox_int = type { i32 }
@thrd_success = global i32 0
@.str = [9 x i8] c"got: %d\0A\00"
define i32 @consume_thrd(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.mbox_int*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to %struct.mbox_int*
store %struct.mbox_int* %7, %struct.mbox_int** %3
br label %8
8: ; preds = %16, %1
%9 = load %struct.mbox_int*, %struct.mbox_int** %3
%10 = call i32 @mbox_get(%struct.mbox_int* %9, i32* %4)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = load i32, i32* @thrd_success
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %8
%17 = load i32, i32* %4
%18 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %8
}

LLVM IR (-O2):
%struct.mbox_int = type { i32 }
@thrd_success = global i32 0
@.str = [9 x i8] c"got: %d\0A\00"
define i32 @consume_thrd(i8* %0) {
%2 = alloca i32
%3 = bitcast i8* %0 to %struct.mbox_int*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @mbox_get(%struct.mbox_int* %3, i32* %2)
%6 = load i32, i32* @thrd_success
%7 = icmp eq i32 %5, %6
br i1 %7, label %10, label %8
8: ; preds = %10, %1
%9 = call i32 (...) @abort()
unreachable
10: ; preds = %1, %10
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 @mbox_get(%struct.mbox_int* %3, i32* %2)
%14 = load i32, i32* @thrd_success
%15 = icmp eq i32 %13, %14
br i1 %15, label %10, label %8
}