#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*/ urle_user_name;
typedef int /*<<< orphan*/ urle_login_token;

/* Variables and functions */
scalar_t__ rc_url_encode(char *, int, char const *);
int snprintf(char *, size_t, char *, char *, char *, unsigned int, int);
int rc_url_get_unlock_list(char *buffer, size_t size, const char *user_name,
                           const char *login_token, unsigned gameid,
                           int hardcore) {
  char urle_user_name[64];
  char urle_login_token[64];
  int written;
  if (rc_url_encode(urle_user_name, sizeof(urle_user_name), user_name) != 0) {
    return -1;
  }
  if (rc_url_encode(urle_login_token, sizeof(urle_login_token), login_token) !=
      0) {
    return -1;
  }
  written =
      snprintf(buffer, size,
               "http://retroachievements.org/"
               "dorequest.php?r=unlocks&u=%s&t=%s&g=%u&h=%d",
               urle_user_name, urle_login_token, gameid, hardcore ? 1 : 0);
  return (size_t)written >= size ? -1 : 0;
}


x86 assembly (clang, -O0):
<rc_url_get_unlock_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x40,%esi
call   1030 <rc_url_encode@plt>
cmp    $0x0,%rax
je     116b <rc_url_get_unlock_list+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <rc_url_get_unlock_list+0xcf>
lea    -0xb0(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x40,%esi
call   1030 <rc_url_encode@plt>
cmp    $0x0,%rax
je     1196 <rc_url_get_unlock_list+0x76>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <rc_url_get_unlock_list+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x70(%rbp),%rcx
lea    -0xb0(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%r10d
xor    %eax,%eax
mov    $0x1,%edx
cmp    $0x0,%r10d
cmovne %edx,%eax
lea    0xe3a(%rip),%rdx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
mov    %eax,-0xb4(%rbp)
movslq -0xb4(%rbp),%rdx
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    %rsi,%rdx
cmovae %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_url_get_unlock_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %r9d,%r13d
mov    %r8d,%r14d
mov    %rcx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x50(%rsp),%rdi
mov    $0x40,%esi
call   1030 <rc_url_encode@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    11a4 <rc_url_get_unlock_list+0x84>
lea    0x10(%rsp),%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1030 <rc_url_encode@plt>
test   %rax,%rax
jne    11a4 <rc_url_get_unlock_list+0x84>
xor    %eax,%eax
test   %r13d,%r13d
setne  %al
mov    %eax,(%rsp)
lea    0xe7e(%rip),%rdx
lea    0x50(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%r9d
call   1040 <snprintf@plt>
cltq
xor    %ebp,%ebp
cmp    %r15,%rax
adc    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [73 x i8] c"http://retroachievements.org/dorequest.php?r=unlocks&u=%s&t=%s&g=%u&h=%d\00"
define i32 @rc_url_get_unlock_list(i8* %0, i64 %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca [64 x i8]
%15 = alloca [64 x i8]
%16 = alloca i32
store i8* %0, i8** %8
store i64 %1, i64* %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %14, i64 0, i64 0
%18 = load i8*, i8** %10
%19 = call i64 @rc_url_encode(i8* %17, i32 64, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %6
store i32 -1, i32* %7
br label %45
22: ; preds = %6
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%24 = load i8*, i8** %11
%25 = call i64 @rc_url_encode(i8* %23, i32 64, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 -1, i32* %7
br label %45
28: ; preds = %22
%29 = load i8*, i8** %8
%30 = load i64, i64* %9
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %14, i64 0, i64 0
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %15, i64 0, i64 0
%33 = load i32, i32* %12
%34 = load i32, i32* %13
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 1, i32 0
%38 = call i32 @snprintf(i8* %29, i64 %30, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %32, i32 %33, i32 %37)
store i32 %38, i32* %16
%39 = load i32, i32* %16
%40 = sext i32 %39 to i64
%41 = load i64, i64* %9
%42 = icmp uge i64 %40, %41
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 -1, i32 0
store i32 %44, i32* %7
br label %45
45: ; preds = %28, %27, %21
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
@.str = [73 x i8] c"http://retroachievements.org/dorequest.php?r=unlocks&u=%s&t=%s&g=%u&h=%d\00"
define i32 @rc_url_get_unlock_list(i8* %0, i64 %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca [64 x i8]
%8 = alloca [64 x i8]
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%11 = call i64 @rc_url_encode(i8* %9, i32 64, i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %6
%14 = call i64 @rc_url_encode(i8* %10, i32 64, i8* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = icmp ne i32 %5, 0
%18 = zext i1 %17 to i32
%19 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10, i32 %4, i32 %18)
%20 = sext i32 %19 to i64
%21 = icmp uge i64 %20, %1
%22 = sext i1 %21 to i32
br label %23
23: ; preds = %13, %6, %16
%24 = phi i32 [ %22, %16 ], [ -1, %6 ], [ -1, %13 ]
ret i32 %24
}