#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 int /*<<< orphan*/ context;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int const);
char *strchr(char *, char);
int swap_context(char *str, const unsigned int context) {
  char *s;
  s = strchr(str, '@');
  if (s == NULL || context == 0)
    return -1;
  s++;
  snprintf(s, sizeof(context), "%u", context);
  return 0;
}


x86 assembly (clang, -O0):
<swap_context>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1156 <swap_context+0x36>
cmpl   $0x0,-0x14(%rbp)
jne    1162 <swap_context+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <swap_context+0x6d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x4,%esi
lea    0xe7f(%rip),%rdx
call   1040 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_context>:
push   %rbx
mov    %esi,%ebx
mov    $0x40,%esi
call   1030 <strchr@plt>
mov    $0xffffffff,%ecx
test   %ebx,%ebx
je     1157 <swap_context+0x37>
test   %rax,%rax
je     1157 <swap_context+0x37>
add    $0x1,%rax
lea    0xeba(%rip),%rdx
mov    %rax,%rdi
mov    $0x4,%esi
mov    %ebx,%ecx
call   1040 <snprintf@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
define i32 @swap_context(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i8* @strchr(i8* %7, i8 signext 64)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store i32 -1, i32* %3
br label %21
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = load i32, i32* %5
%20 = call i32 @snprintf(i8* %18, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 0, i32* %3
br label %21
21: ; preds = %15, %14
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
define i32 @swap_context(i8* %0, i32 %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 64)
%4 = icmp eq i8* %3, null
%5 = icmp eq i32 %1, 0
%6 = or i1 %5, %4
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %3, i64 1
%9 = tail call i32 @snprintf(i8* %8, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %10
10: ; preds = %2, %7
%11 = phi i32 [ 0, %7 ], [ -1, %2 ]
ret i32 %11
}